RinteRface / shinydashboardPlus

extensions for shinydashboard
https://shinydashboardplus.rinterface.com
Other
454 stars 77 forks source link

Updating dashboardLabel dynamically #35

Closed sasshiburi closed 5 years ago

sasshiburi commented 5 years ago

I have a shiny app where I have am using a dashboardLabel as kind a sort of placeholder UI element to show some text. The issue is that I cannot seem to be able to update the label because it doesn't appear as there is a way for me to actually reference it.

I have tried something like the following:

# some code ...

jobidinfo <- 'some text'
body <- dashboardBody(
  dashboardLabel(jobidinfo, status = "info"),
  actionButton("new_job", "New Job")

#  some more stuff ...
)

# set up server ...

observeEvent(input$new_job, {
  jobidinfo <- 'some new text'
  session$reload()
})

However, my solution doesn't actually update the label text.

DivadNojnarg commented 5 years ago

You can generate your label in the server and dynamically update it:

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

shinyApp(
  ui = dashboardPagePlus(
    header = dashboardHeaderPlus(
      enable_rightsidebar = TRUE,
      rightSidebarIcon = "gears"
    ),
    sidebar = dashboardSidebar(),
    body = dashboardBody(
      actionButton("new_job", "New Job"),
      uiOutput("label")
    ),
    rightsidebar = rightSidebar(),
    title = "DashboardPage"
  ),
  server = function(input, output) {

    output$label <- renderUI({
      dashboardLabel(
        if (input$new_job) "some new text" else "some text", 
        status = "info"
      )
    })
  }
)