【发布时间】:2017-06-14 19:49:22
【问题描述】:
我正在尝试构建一个应用程序,允许用户从预先提供的列表中选择一个或多个函数(模块),然后根据他们的选择,为该函数的各种参数选择值。
基本上,我正在尝试重建 renderUI 调用树,以便当闪亮的反应部分发生并且调用服务器函数时,如果 input$abcd.in 不为 NULL,则使用不同的参数运行 renderUI 函数取决于 input$abcd.in 的值是什么。
错误似乎是 set_output_automatically 函数的输入参数的长度为 0,但我不知道下一步该做什么。
这是一个简化的例子
library(shiny)
arg.info <- list(
list(choices = c("Yes" = T, "No" = F),
prompt = quote(paste("Remove Missing Values for analysis?")),
type = "radioButtons"),
list(choices = c("not" = 0, "some" = 1, "very" = 3),
prompt = quote(paste("how cool are you?")),
type = "checkboxGroupInput"))
set_output_automatically <- function(input, arg.info){
if(input[1] > 3){
arg.info <- arg.info[[1]]
} else {
arg.info <- arg.info[[2]]
}
renderUI({
call(arg.info$type, paste0(input$abcd, ".in"), label = arg.info$prompt,
choices = arg.info$choices)
})
}
ui <- fluidPage(
uiOutput('abcd'),
textOutput('value'),
uiOutput('result')
)
server <- function(input, output){
output$abcd <- renderUI({
checkboxGroupInput('abcd.in', 'sample',
choices = c('wowe'= 1,
'such' = 2,
'choice' = 3,
'very' = 4,
'programe' = 5))
})
output$value <- renderPrint({input$abcd.in})
output$result <- reactive(set_output_automatically(input$abcd.in, arg.info))
}
shinyApp(ui, server)
【问题讨论】:
标签: r functional-programming shiny