【发布时间】:2021-12-09 04:46:16
【问题描述】:
我使用this 教程将暗模式切换器引入我的应用程序。 我希望应用程序在未选中复选框时返回默认主题。 我在dashboardthemes 库中找不到“默认”主题,也找不到在shinyDashboardThemeDIY() 函数中使用的默认主题定义。 任何线索将不胜感激。
在一段可重现的代码下方(它在第一阶段完美运行,但当我取消选中复选框时没有任何反应:主题保持黑暗而不是再次变为白色和蓝色)
library(shiny)
library(shinydashboard)
library(dashboardthemes)
# Functions
uiDarkModeCheckBox <- function()
{
ns <- NS("moduleChangeTheme")
checkbox <- tagList(
checkboxInput(
inputId = ns("dbxChangeTheme"),
label = "Dark Mode",
value = FALSE
)
)
return(checkbox)
}
uiChangeThemeOutput <- function()
{
ns <- NS("moduleChangeTheme")
themeOutput <- tagList(
uiOutput(ns("uiChangeTheme"))
)
return(themeOutput)
}
serverChangeTheme <- function(input, output, session)
{
observeEvent(
input$dbxChangeTheme,
{
output$uiChangeTheme <- renderUI({
if (input$dbxChangeTheme == TRUE) {
uiChangeThemeOutput()
shinyDashboardThemes(theme = "grey_dark")
}
})
}
)
}
# UI
ui <- dashboardPage(dashboardHeader(),
dashboardSidebar(),
dashboardBody(
uiChangeThemeOutput(),
tabItem(tabName = "inputs_tab",
uiDarkModeCheckBox(),
)
)
)
# SERVER
server <- function(input, output, session) {
callModule(module = serverChangeTheme, id = "moduleChangeTheme")
}
shinyApp(ui, server)
【问题讨论】:
-
请提供一些您目前尝试过的可重现代码。
-
添加了一段可重现的代码
标签: r shiny shinydashboard