Exploring the captivating shiny dashboard example illustrated below (adapted from ). One might ponder if there's a way to seamlessly scroll within one tab item, and upon transitioning to another tab item by selecting it in the sidebar, end up at the top of the new item instead of its previous position?
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(
sidebarMenu(
style = "position: fixed; overflow: visible;",
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", tabName = "widgets", icon = icon("th"))
)
),
## Body content
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "dashboard",
fluidRow(
box(plotOutput("plotA", height = 250)),
box(
title = "Controls",
sliderInput("sliderA", "Number of observations:", 1, 100, 50)
)
),
fluidRow(
box(plotOutput("plotB", height = 250)),
box(
title = "Controls",
sliderInput("sliderB", "Number of observations:", 1, 100, 50)
)
),
fluidRow(
box(plotOutput("plotC", height = 250)),
box(
title = "Controls",
sliderInput("sliderC", "Number of observations:", 1, 100, 50)
)
),
fluidRow(
box(plotOutput("plotD", height = 250)),
box(
title = "Controls",
sliderInput("sliderD", "Number of observations:", 1, 100, 50)
)
),
fluidRow(
box(plotOutput("plotE", height = 250)),
box(
title = "Controls",
sliderInput("sliderE", "Number of observations:", 1, 100, 50)
)
),
fluidRow(
box(plotOutput("plotF", height = 250)),
box(
title = "Controls",
sliderInput("sliderF", "Number of observations:", 1, 100, 50)
)
)
),
# Second tab content
tabItem(tabName = "widgets",
h2("Widgets tab content"),
fluidRow(
box(plotOutput("plot1", height = 250)),
box(
title = "Controls",
sliderInput("slider1", "Number of observations:", 1, 100, 50)
)
),
fluidRow(
box(plotOutput("plot2", height = 250)),
box(
title = "Controls",
sliderInput("slider2", "Number of observations:", 1, 100, 50)
)
),
fluidRow(
box(plotOutput("plot3", height = 250)),
box(
title = "Controls",
sliderInput("slider3", "Number of observations:", 1, 100, 50)
)
),
fluidRow(
box(plotOutput("plot4", height = 250)),
box(
title = "Controls",
sliderInput("slider4", "Number of observations:", 1, 100, 50)
)
),
fluidRow(
box(plotOutput("plot5", height = 250)),
box(
title = "Controls",
sliderInput("slider5", "Number of observations:", 1, 100, 50)
)
),
fluidRow(
box(plotOutput("plot6", height = 250)),
box(
title = "Controls",
sliderInput("slider6", "Number of observations:", 1, 100, 50)
)
)
)
)
)
)
server <- function(input, output) {
set.seed(122)
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider1)]
hist(data)
})
output$plot2 <- renderPlot({
data <- histdata[seq_len(input$slider2)]
hist(data)
})
output$plot3 <- renderPlot({
data <- histdata[seq_len(input$slider3)]
hist(data)
})
output$plot4 <- renderPlot({
data <- histdata[seq_len(input$slider4)]
hist(data)
})
output$plot5 <- renderPlot({
data <- histdata[seq_len(input$slider5)]
hist(data)
})
output$plot6 <- renderPlot({
data <- histdata[seq_len(input$slider6)]
hist(data)
})
output$plotA <- renderPlot({
data <- histdata[seq_len(input$sliderA)]
hist(data)
})
output$plotB <- renderPlot({
data <- histdata[seq_len(input$sliderB)]
hist(data)
})
output$plotC <- renderPlot({
data <- histdata[seq_len(input$sliderC)]
hist(data)
})
output$plotD <- renderPlot({
data <- histdata[seq_len(input$sliderD)]
hist(data)
})
output$plotE <- renderPlot({
data <- histdata[seq_len(input$sliderE)]
hist(data)
})
output$plotF <- renderPlot({
data <- histdata[seq_len(input$sliderF)]
hist(data)
})
}
shinyApp(ui, server)