【问题标题】:Display box after actionButton is pressed in a shiny dashboard在闪亮的仪表板中按下 actionButton 后的显示框
【发布时间】:2021-12-14 13:47:33
【问题描述】:

我在下面有闪亮的应用程序,我希望仅在按下 actionButton 时才显示 box。否则,用户会感到困惑,因为他看到一个没有绘图的空框。

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)

shinyApp(
  ui = tags$body(class="skin-blue sidebar-mini control-sidebar-open",dashboardPage(
    options = list(sidebarExpandOnHover = TRUE),
    header = dashboardHeader(title = "Investment Advisor Monitoring - Insider Trading",titleWidth = 450),
    
    sidebar = dashboardSidebar(minified = F, collapsed = F,
                               actionButton("go", "Go"),
                               numericInput("n", "n", 50)
    ),
    body = dashboardBody(
      box(
        title = "StockPrice Reaction Around The Event Date", status = "primary", solidHeader = TRUE,
        collapsible = TRUE,
      plotOutput("plot"))
      
    ),
    title = "DashboardPage"
  )),
  server = function(input, output) { 
    
    randomVals <- eventReactive(input$go, {
      runif(input$n)
    })
    
    output$plot <- renderPlot({
      hist(randomVals())
    })
  }
)

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    shinyjs::hidden()shinyjs::show()observeEvent() 一起使用。

    你的例子现在变成了:

    library(shiny)
    library(shinydashboard)
    library(shinydashboardPlus)
    library(shinyjs)
    
    ui <- tags$body(
      class="skin-blue sidebar-mini control-sidebar-open", 
      
      dashboardPage(
        options = list(sidebarExpandOnHover = TRUE), 
        
        # ----header----
        header = dashboardHeader(
          title = "Investment Advisor Monitoring - Insider Trading",
          titleWidth = 450
        ), 
        
        # ----sidebar----
        sidebar = dashboardSidebar(
          minified = FALSE, 
          collapsed = FALSE,
          actionButton("go", "Go"),
          numericInput("n", "n", 50)
        ), 
        
        # ----body----
        body = dashboardBody(
          useShinyjs(), # MUST include this line
          
          # ----hiddenbox----
          shinyjs::hidden(
            div(
              id = "hiddenbox", 
              
              box(
                title = "StockPrice Reaction Around The Event Date", 
                status = "primary", 
                solidHeader = TRUE,
                collapsible = TRUE,
                plotOutput("plot")
              )
            )
          )
        )
      )
    )
    
    
    server <- function(input, output, session) { 
      randomVals <- eventReactive(input$go, {
        runif(input$n)
      })
      
      # ----show hiddenbox----
      observeEvent(input$go, {
        shinyjs::show(id = "hiddenbox")
      })
      
      output$plot <- renderPlot({
        hist(randomVals())
      })
    }
    
    shinyApp(ui, server)
    
    
    

    【讨论】:

    • 非常感谢它的工作原理
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-11
    • 2015-04-22
    • 2018-11-08
    • 2018-05-18
    • 1970-01-01
    • 2021-09-05
    • 1970-01-01
    相关资源
    最近更新 更多