1 回答
TA贡献1874条经验 获得超12个赞
R中的非输入变量不会传递给JavaScript,作为一种解决方法,我将字符向量构建到JS数组中,并将其传递到条件中。因此,在这种情况下通过的实际条件是哪个执行您想要的操作。['elephant', 'human', 'dog', 'cat'].includes(input.animals)
library(shiny)
birds <- c("finch","robin","crow","duck")
mammals <- c("elephant", "human", "dog", 'cat')
ui <- fluidPage(
titlePanel("Select Conditional"),
mainPanel(
column(4,
selectizeInput(inputId = "animals",
label = "Select An Animal",
choices= list('Examples of Birds' = birds,
'Example of mammals' = mammals)
)),
column(8,
conditionalPanel(condition = paste0(paste0("[",toString(paste0("'",mammals,"'")),"]"),".includes(input.animals)"),
textOutput("text")))
))
server <- function(input, output) {
output$text <- renderText({"This is a mammal."})
}
shinyApp(ui = ui, server = server)
添加回答
举报