我使用这教程向我的应用程序引入了黑暗模式切换程序。我希望应用程序返回到默认主题时,复选框没有选中。我在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)发布于 2021-12-11 00:11:16
根据您的需要defaultTheme = "grey_light"设置默认主题。
uiChangeThemeDropdown <- function(dropDownLabel = "Change Theme", defaultTheme = "grey_light")
{
changeThemeChoices <- c(
"Blue gradient" = "blue_gradient",
"Flat Red" = "flat_red",
"Grey light" = "grey_light",
"Grey dark" = "grey_dark",
"OneNote" = "onenote",
"Poor man's Flatly" = "poor_mans_flatly",
"Purple gradient" = "purple_gradient"
)https://stackoverflow.com/questions/69678582
复制相似问题