1 回答
TA貢獻1874條經(jīng)驗 獲得超12個贊
R中的非輸入變量不會傳遞給JavaScript,作為一種解決方法,我將字符向量構建到JS數(shù)組中,并將其傳遞到條件中。因此,在這種情況下通過的實際條件是哪個執(zhí)行您想要的操作。['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)
添加回答
舉報
