考虑下面的玩具示例.当复选框为=TRUE但似乎没有效果时,我试图显示不同的图形.我使用"switch"根据其标签显示图形.感谢您提供有关如何使用条件语句(if)显示备用图形的提示.
library(shiny)
mytest <- c("first","second")
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
selectInput(inputId = "test",
label = "Test",
choices = mytest,
selected = "first"),
checkboxInput("checkbox","check this box",FALSE)),
mainPanel(
plotOutput("distPlot")
)))
server <- function(input, output) {
output$distPlot <- renderPlot({
switch(input$test,
"first" = plot(rnorm(100)),
if("checkbox" == FALSE){
"second" = plot(rnorm(1000),col="blue")
} else{
#I want the graphic below to be displayed when the checkbox = TRUE or checked
"second" = plot(rnorm(10000),col='red')
}
)
})
}
shinyApp(ui = ui, server = server)