在闪亮的仪表板上显示基于闪亮小部件的框

时间:2019-10-05 13:22:11

标签: r shiny shinydashboard

是否可以根据box选择在发光的仪表板上显示selectInput()

## 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)

1 个答案:

答案 0 :(得分:1)

要实现交互性,您需要在服务器代码中动态生成UI。

## 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)