Dynamically display a dashboardPage

后端 未结 2 574
长情又很酷
长情又很酷 2021-02-19 09:03

I have a functional shiny app that uses the shinydashboard package.

A new feature requires user-specific behavior (e.g. use different data sets for differen

2条回答
  •  眼角桃花
    2021-02-19 09:29

    It also works with invalidateLater(), but also only temporary.

    library(shiny)
    library(shinydashboard)
    
    ui <- uiOutput("ui")
    
    server <- function(input, output, session) {
    
      state <- reactiveValues(LoggedIn = FALSE)
    
      observeEvent(input$btn_login, {
        state$LoggedIn = !state$LoggedIn
      })
    
      ui1 <- reactive({
        fixedPage(actionButton("btn_login", "Login"))
      })
    
      ui2 <- reactive({
        ui2 <- dashboardPage(dashboardHeader(), dashboardSidebar(), dashboardBody(
           sliderInput("slider", "slider", min = 1, max = 10, value = 2)
         ))
        invalidateLater(100, session)
        ui2
      })
    
      output$ui <- renderUI({if (!state$LoggedIn) ui1() else ui2()})
    
    }
    
    shinyApp(ui, server)
    

提交回复
热议问题