在shinydashboard的头部设置一个下拉按钮,用于选择主题。

问题描述 投票:0回答:1

我想在shinydashboard头部放一个下拉菜单,以便更换仪表盘主题。我的闪亮的应用程序是像下面。我不能使应用程序的工作。 我得到的是错误信息。

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

好像仪表板区域不接受那些典型的闪亮小部件?头部区域是放这个功能的最好地方。 有谁知道我如何能让它工作?非常感谢。

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) { }
)
r shiny shinydashboard
1个回答
1
投票

你不能把 "X[[i]],... "放入 dropdownButtondashboardHeader.

相反,你可以把它放在 dashboardBodydashboardSidebar 并把它更新成这样。

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))
    }
)
© www.soinside.com 2019 - 2024. All rights reserved.