Consider the code below. It produces Shiny dashboard with two menu items where every time the user checks a box on either tab, a histogram is displayed. However, after a certain point (after the second histogram on every tab is rendered), every time a new element histogram is rendered, the user has to scroll down by hand.
What I am looking for is a solution where every time a new element is rendered further down on the tab of a Shiny dashboard, the tab is immediately scrolled down to the bottom, so the new element is fully seen, and that it applies to all tabs of the dashboard. This example is with plots (histograms) but it can be any kind of output.
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)
Can someone help?