我在renderUI上遇到问题,在任何地方都找不到解决方案。可能我是在向Google问错了一个问题,而不仅仅是一个基本的R问题。
我在R中有一个函数,该函数根据输入将返回表或文本。因此,我以这种方式在server.R中创建了两个选项:
output$table <- renderTable {(
x <- function (y)
print(x)
)}
output$text <- renderText {(
x <- function (y)
print(x)
)}
如果我将两个输出都放到renderUI中,将始终给我一个错误。对于textOutput如果输出是一个表:
Error: argument 1 (type 'list') cannot be handled by 'cat'
和
Error:no applicable method for 'xtable' applied to an object of class "character"
反之亦然。
我的问题是否有办法捕获此错误,并在renderUI中使用if语句仅显示两者之一?如果需要,我在这里为您提供更多详细信息。
[编辑]
服务器
library(shiny)
library(drsmooth)
shinyServer(function(input, output,session) {
-- upload dataframe and input management goes here --
output$nlbcd <- renderTable({
nlbcd<-nlbcd(dosecolumn="Dose", targetcolumn=response(),cutoffdose=cutoff(),data=data1())
print(nlbcd)
})
output$nlbcdText <- renderText({
nlbcd<-nlbcd(dosecolumn="Dose", targetcolumn=response(),cutoffdose=cutoff(),data=data1())
print(nlbcd)
})
output$tb <- renderUI({
tableOutput("nlbcd"),
textOutput("nlbcdText")
})
})
您在这里遇到了一些问题,该函数将返回不同的类,包括带有解释的错误和警告。这是此函数可能发生的独立示例,建议您在代码中包含TryCatch:
用户界面
shinyUI(
pageWithSidebar(
headerPanel("drsmooth"), sidebarPanel(
numericInput("num", label = h3("Choose 'cutoffdose'"), value = 0)
),
mainPanel(
verbatimTextOutput('current')
)
)
)
服务器
library(drsmooth)
shinyServer(function(input, output, session) {
output$current <- renderPrint({
dose <- input$num
tryCatch(isolate(nlbcd("dose", "MF_Log", cutoffdose=dose, data=DRdata)),
error=function(e) {
cat(isolate(conditionMessage(e)))
}
)
})
})
样本输出:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句