2

I want to put a dropdown menu on shinydashboard header for dashboard theme change. My shiny app is like below. I could not make the app work. What I got is error message;

Error in FUN(X[[i]], ...) : Expected tag to be of type li

It seems like the dashboard area does not accept those typical shiny widgets? The header area is the best place to put this functionality. Does anyone know how I can make that work? Thanks a lot.

library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(dashboardthemes)


header <- dashboardHeader(
    title = "Dashboard Demo",
    dropdownButton(

        tags$h3("List of Themes:"),

        radioButtons(inputId = 'theme',
                     label = 'Dashboard Theme',
                     choices = c('blue_gradient', 'boe_website', 'grey_light','grey_dark',
                                 'onenote', 'poor_mans_flatly', 'purple_gradient'),
                     selected = 'grey_dark',
                     inline=FALSE),

        circle = TRUE, status = "primary",
        icon = icon("window-maximize"), width = "300px",

        tooltip = tooltipOptions(title = "Click to change dashboard theme")
    )
)

shinyApp(
    ui = dashboardPage(
        header,
        dashboardSidebar(),
        dashboardBody(
            shinyDashboardThemes(
                theme = input$theme
            ),
        )
    ),
    server = function(input, output) { }
)
zesla
  • 11,155
  • 16
  • 82
  • 147

1 Answers1

2

You can not put the dropdownButton in the dashboardHeader.

Instead you can put it in the dashboardBody or dashboardSidebar and have it updated like this :

library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(dashboardthemes)

shinyApp(
  ui = dashboardPage(
    dashboardHeader(title = "Dashboard Demo"),
    dashboardSidebar(),
    dashboardBody(
      dropdownButton(
        radioButtons(inputId = 'theme',
                     label = 'Dashboard Theme',
                     choices =  c('blue_gradient', 'boe_website', 'grey_light','grey_dark',
                                  'onenote', 'poor_mans_flatly', 'purple_gradient'))
      ),
      uiOutput("myTheme")
    )
  ),
  server = function(input, output) { 
    output$myTheme <- renderUI( shinyDashboardThemes(theme = input$theme))
    }
)
HubertL
  • 19,246
  • 3
  • 32
  • 51
  • thanks. Is there any way to put something else in the header that I can choose from a list of themes? @HubertL – zesla May 07 '20 at 03:28
  • Have a look at [this question](https://stackoverflow.com/questions/46231234/login-button-in-shinydashboard-dashboardheader) – HubertL May 07 '20 at 18:47