我的 renderUI 有问题,但在任何地方都找不到解决方案。可能我向谷歌问了错误的问题,不仅仅是一个闪亮的问题,而是一个基本的 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'
and
Error:no applicable method for 'xtable' applied to an object of class "character"
如果反之亦然。
我的问题是有没有办法捕获此错误并在 renderUI 中使用 if 语句仅显示两者之一?
如果您需要的话,我会在这里为您提供更多详细信息。
[EDIT]
server.R
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")
})
})