R Shiny 在后台加载隐藏的侧边栏(使用 bs4Dash 包)
R Shiny load hidden sidebar in the background (using bs4Dash package)
我已经ui使用 bs4Dash 制作了一个 R Shiny 仪表板。这个包允许我在右侧为输入选择器创建一个栏,这样我就可以使用左侧菜单进行导航。当应用程序启动时,右侧的 bs4DashControlbar 是隐藏的。问题是,如果我在服务器端创建一个选择器并在 ui 中使用 uiOutput(),它不会呈现 - 即我的两个选择器没有加载。我发现是这种情况,因为控制栏开始是隐藏的(我想要的)。我正在尝试让控制栏中的选择器始终呈现为可见。
在下面查看我的尝试。请注意,当“controlbar_collapsed”行取消注释时,我的选择器加载得很好。但同样,我不希望控制栏在加载时可见,我还希望它始终更新,即使有人隐藏了控制栏。我的修复尝试在底部附近被注释掉了。我尝试使用带 suspendWhenHidden 的 outputOptions。我认为这是正确的道路,但我无法让它发挥作用。或者有更好的方法吗?
library(shiny)
library(bs4Dash)
shiny::shinyApp(
ui = bs4DashPage(
old_school = FALSE,
sidebar_min = TRUE,
sidebar_collapsed = FALSE,
#controlbar_collapsed = FALSE, ###Uncomment this line and it loads just fine
controlbar_overlay = TRUE,
title = "Basic Dashboard",
navbar = bs4DashNavbar(),
sidebar = bs4DashSidebar(),
controlbar = bs4DashControlbar(inputId = "Controller",
sliderInput("slider", "Number of observations:", 1, 100, 50),
uiOutput("TimeFrame"),
uiOutput("Metrics")
),
footer = bs4DashFooter(),
body = bs4DashBody()
),
server = function(input, output) {
output$TimeFrame <- renderUI({selectInput("TimeFrame", "Select Time Frame:",
c("Last 01 Wks", "Last 04 Wks", "Last 13 Wks", "Last 52 Wks", "Year to Date"),
multiple=FALSE)})
output$Metrics <- renderUI({selectInput("Metrics", "Select a Metric:",
c("Metric A", "Metric B"),
multiple=FALSE)})
#outputOptions(output, "Controller", suspendWhenHidden = FALSE) #This is what I tried
}
)
library(shiny)
library(shinyjs)
library(bs4Dash)
shiny::shinyApp(
ui = fluidPage(
useShinyjs(),
bs4DashPage(
old_school = FALSE,
sidebar_min = TRUE,
sidebar_collapsed = FALSE,
# controlbar_collapsed = FALSE, ###Uncomment this line and it loads just fine
controlbar_overlay = TRUE,
title = "Basic Dashboard",
navbar = bs4DashNavbar(),
sidebar = bs4DashSidebar(),
controlbar = bs4DashControlbar(inputId = "Controller",
sliderInput("slider", "Number of observations:", 1, 100, 50),
shinyjs::hidden(div(id = "MyPanel",
uiOutput("TimeFrame"),
uiOutput("Metrics")))
),
footer = bs4DashFooter(),
body = bs4DashBody()
)),
server = function(input, output) {
output$TimeFrame <- renderUI({selectInput("TimeFrame", "Select Time Frame:",
c("Last 01 Wks", "Last 04 Wks", "Last 13 Wks", "Last 52 Wks", "Year to Date"),
multiple=FALSE)})
output$Metrics <- renderUI({selectInput("Metrics", "Select a Metric:",
c("Metric A", "Metric B"),
multiple=FALSE)})
observe({
if (input$Controller) {
shinyjs::show("MyPanel")
} else {
shinyjs::hide("MyPanel")
}
})
# outputOptions(output, "Controller", suspendWhenHidden = FALSE) #This is what I tried
}
)
我已经ui使用 bs4Dash 制作了一个 R Shiny 仪表板。这个包允许我在右侧为输入选择器创建一个栏,这样我就可以使用左侧菜单进行导航。当应用程序启动时,右侧的 bs4DashControlbar 是隐藏的。问题是,如果我在服务器端创建一个选择器并在 ui 中使用 uiOutput(),它不会呈现 - 即我的两个选择器没有加载。我发现是这种情况,因为控制栏开始是隐藏的(我想要的)。我正在尝试让控制栏中的选择器始终呈现为可见。
在下面查看我的尝试。请注意,当“controlbar_collapsed”行取消注释时,我的选择器加载得很好。但同样,我不希望控制栏在加载时可见,我还希望它始终更新,即使有人隐藏了控制栏。我的修复尝试在底部附近被注释掉了。我尝试使用带 suspendWhenHidden 的 outputOptions。我认为这是正确的道路,但我无法让它发挥作用。或者有更好的方法吗?
library(shiny)
library(bs4Dash)
shiny::shinyApp(
ui = bs4DashPage(
old_school = FALSE,
sidebar_min = TRUE,
sidebar_collapsed = FALSE,
#controlbar_collapsed = FALSE, ###Uncomment this line and it loads just fine
controlbar_overlay = TRUE,
title = "Basic Dashboard",
navbar = bs4DashNavbar(),
sidebar = bs4DashSidebar(),
controlbar = bs4DashControlbar(inputId = "Controller",
sliderInput("slider", "Number of observations:", 1, 100, 50),
uiOutput("TimeFrame"),
uiOutput("Metrics")
),
footer = bs4DashFooter(),
body = bs4DashBody()
),
server = function(input, output) {
output$TimeFrame <- renderUI({selectInput("TimeFrame", "Select Time Frame:",
c("Last 01 Wks", "Last 04 Wks", "Last 13 Wks", "Last 52 Wks", "Year to Date"),
multiple=FALSE)})
output$Metrics <- renderUI({selectInput("Metrics", "Select a Metric:",
c("Metric A", "Metric B"),
multiple=FALSE)})
#outputOptions(output, "Controller", suspendWhenHidden = FALSE) #This is what I tried
}
)
library(shiny)
library(shinyjs)
library(bs4Dash)
shiny::shinyApp(
ui = fluidPage(
useShinyjs(),
bs4DashPage(
old_school = FALSE,
sidebar_min = TRUE,
sidebar_collapsed = FALSE,
# controlbar_collapsed = FALSE, ###Uncomment this line and it loads just fine
controlbar_overlay = TRUE,
title = "Basic Dashboard",
navbar = bs4DashNavbar(),
sidebar = bs4DashSidebar(),
controlbar = bs4DashControlbar(inputId = "Controller",
sliderInput("slider", "Number of observations:", 1, 100, 50),
shinyjs::hidden(div(id = "MyPanel",
uiOutput("TimeFrame"),
uiOutput("Metrics")))
),
footer = bs4DashFooter(),
body = bs4DashBody()
)),
server = function(input, output) {
output$TimeFrame <- renderUI({selectInput("TimeFrame", "Select Time Frame:",
c("Last 01 Wks", "Last 04 Wks", "Last 13 Wks", "Last 52 Wks", "Year to Date"),
multiple=FALSE)})
output$Metrics <- renderUI({selectInput("Metrics", "Select a Metric:",
c("Metric A", "Metric B"),
multiple=FALSE)})
observe({
if (input$Controller) {
shinyjs::show("MyPanel")
} else {
shinyjs::hide("MyPanel")
}
})
# outputOptions(output, "Controller", suspendWhenHidden = FALSE) #This is what I tried
}
)