简体   繁体   中英

Display a box based on shiny widget in a shiny dashboard

Is it possible to display or not a box in a shiny dashboard based on a selectInput() choice?

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
selectInput("sel","Select",c("Display","Not"))
),
  dashboardBody(
box()
)
)

server <- function(input, output) { }

shinyApp(ui, server)

For interactivity, you need to generate UI dynamically in server codes.

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
    dashboardHeader(),
    dashboardSidebar(
        selectInput("sel","Select",c("Display","Not"))
    ),
    dashboardBody(
        uiOutput("conditionalBox")
    )
)

server <- function(input, output) {
    output$conditionalBox <- renderUI({
        if(input$sel == "Display"){
            return(
                box(title = "Display when choosing Display in #sel")
            )
        } else {
            return(
                NULL
            )
        }
    })
}

shinyApp(ui, server)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM