【发布时间】:2021-07-03 20:37:05
【问题描述】:
我想创建一个动态用户界面。当我选择"Total" 时,我不想显示任何内容,甚至是一个空框架。我希望仅在选择 "Cancer" 或 " without cancer" 时显示某些内容。
ui<-fluidPage(
titlePanel("Dynamically generated user interface components"),
fluidRow(
column(3, wellPanel(
selectInput("input_type", "Input type",
c("Total","Cancer", "Without cancer"
)
)
)),
column(3, wellPanel(
# This outputs the dynamic UI component
uiOutput("ui")
))
)
)
server<-function(input, output) {
output$ui <- renderUI({
if (is.null(input$input_type))
return()
# Depending on input$input_type, we'll generate a different
# UI component and send it to the client.
switch(input$input_type,
"Cancer" = selectInput("dynamic", "Dynamic",
choices = c("Lung cancer" = "Lung cancer",
"Breast cancer" = "Breast cancer",
"Colon cancer"= "Colon cancer"),),
"Without cancer" = selectInput("dynamic", "Dynamic",
choices = c("Pneumonia" = "Pneumonia",
"Gastro-enteritis" = "Gastro-enteritis",
"Flu"= "Flu"),)
)
})
output$input_type_text <- renderText({
input$input_type
})
output$dynamic_value <- renderPrint({
str(input$dynamic)
})
}
shinyApp(ui,server)
【问题讨论】: