我正在使用包在 Shiny 中构建仪表板,并注意到在 中bs4Dash
包含小部件时出现了一些奇怪的行为。日历小部件显示在输入文本框上方而不是下方,从而阻止用户更改输入的月份或年份(除非在输入中手动输入)。dateRangeInput()
boxSidebar()
infoBox()
我在 的第一个实例中设置了一组四个KPI fluidRow()
,并且box()
包含一个可以使用 的第二个实例中的日期范围输入进行过滤的图fluidRow()
。我怀疑这可能是问题的一部分,因为如果我完全删除包含我的信息框的第一个实例,就不会出现奇怪的日历小部件行为fluidRow()
。以下是最低限度可重现的示例代码:
library(shiny)
library(bs4Dash)
df <- data.frame(
date = as.Date(c("2024-12-20", "2024-12-21")),
value = 1:2
)
ui <- dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
body = dashboardBody(
fluidRow(
lapply(1:4, function(x) {
infoBox(
title = paste0("Info Box ", x),
value = x,
width = 3,
)
})
),
fluidRow(
box(
collapsible = FALSE,
plotOutput("examplePlot", width = "100%"),
sidebar = boxSidebar(
id = "exampleSidebar",
width = 40,
dateRangeInput(
inputId = "exampleDateRangeInput",
label = "Select Date",
format = "M dd, yyyy",
width = "100%"
),
easyClose = FALSE
)
)
)
)
)
server <- function(input, output, session) {
output$examplePlot <- renderPlot({
ggplot2::ggplot(df, ggplot2::aes(date, value)) +
ggplot2::geom_line()
})
}
shinyApp(ui, server)
您可以包含一些自定义 css,并将日期选择器的 z-index 更改为非常高。
z-index
基本上是 html 页面上的层顺序。编辑:我添加了一些小部分,将日期选择器向下推 160 像素,以便弹出窗口不会遮挡顶部的任何框。
shinyApp(用户界面,服务器)
正如你所见,这个方法有效并且没有任何遮挡: