【发布时间】:2020-08-18 21:18:53
【问题描述】:
考虑下面的代码。它生成带有两个菜单项的闪亮仪表板,每次用户选中任一选项卡上的框时,都会显示一个直方图。但是,在某个点之后(在每个选项卡上的第二个直方图被渲染之后),每次渲染一个新的元素直方图时,用户都必须手动向下滚动。
我正在寻找的解决方案是,每次在 Shiny 仪表板的选项卡上进一步向下呈现新元素时,该选项卡会立即向下滚动到底部,因此可以完全看到新元素,并且它适用于仪表板的所有选项卡。此示例带有图(直方图),但它可以是任何类型的输出。
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "My dashboard"),
dashboardSidebar(
menuItem(text = "Tab 1", tabName = "tab1"),
menuItem(text = "Tab 2", tabName = "tab2")
),
dashboardBody(
tabItems(
tabItem(tabName = "tab1",
h1(textOutput(outputId = "header1")),
checkboxInput(inputId = "sepalLng", label = "Histogram - iris, Sepal.Length"),
conditionalPanel(condition = "input.sepalLng",
plotOutput(outputId = "histSepalLng", height = "500px")
),
checkboxInput(inputId = "sepalWdt", label = "Histogram - iris, Sepal.Width"),
conditionalPanel(condition = "input.sepalWdt",
plotOutput(outputId = "histSepalWdt", height = "500px")
),
checkboxInput(inputId = "petalLng", label = "Histogram - iris, Petal.Length"),
conditionalPanel(condition = "input.petalLng",
plotOutput(outputId = "histPetalLng", height = "500px")
),
checkboxInput(inputId = "petalWdt", label = "Histogram - iris, Petal.Width"),
conditionalPanel(condition = "input.petalWdt",
plotOutput(outputId = "histPetalWdt", height = "500px")
)
),
tabItem(tabName = "tab2",
h1(textOutput(outputId = "header2")),
checkboxInput(inputId = "mpg", label = "Histogram - mtcars, mpg"),
conditionalPanel(condition = "input.mpg",
plotOutput(outputId = "histMpg", height = "500px")
),
checkboxInput(inputId = "drat", label = "Histogram - mtcars, drat"),
conditionalPanel(condition = "input.drat",
plotOutput(outputId = "histDrat", height = "500px")
),
checkboxInput(inputId = "wt", label = "Histogram - mtcars, wt"),
conditionalPanel(condition = "input.wt",
plotOutput(outputId = "histWt", height = "500px")
),
checkboxInput(inputId = "qsec", label = "Histogram - mtcars, qsec"),
conditionalPanel(condition = "input.qsec",
plotOutput(outputId = "histQsec", height = "500px")
)
)
)
)
)
server <- function(input, output) {
output$header1 <- renderText({"Tab 1 - iris data"})
output$histSepalLng <- renderPlot(hist(iris$Sepal.Length))
output$histSepalWdt <- renderPlot(hist(iris$Sepal.Width))
output$histPetalLng <- renderPlot(hist(iris$Petal.Length))
output$histPetalWdt <- renderPlot(hist(iris$Petal.Width))
output$header2 <- renderText({"Tab 2 - mtcars data"})
output$histMpg <- renderPlot(hist(mtcars$mpg))
output$histDrat <- renderPlot(hist(mtcars$drat))
output$histWt <- renderPlot(hist(mtcars$wt))
output$histQsec <- renderPlot(hist(mtcars$qsec))
}
shinyApp(ui, server)
有人可以帮忙吗?
【问题讨论】:
标签: r shiny shinydashboard autoscroll