I would like to add a scrollbar for a plot in Shiny app, but only the vertical scroll bar appear while horizontal scroll bars do not appear. I attached a small shiny app with minimum elements here to demonstrate the problem.
cat("\014")
unlink(".RData")
rm(list=ls(all.names = TRUE))
# A basic shiny app with a plotOutput
shinyApp(
ui = fluidPage(
sidebarLayout(
sidebarPanel(
),
mainPanel(
column(6,(div(style='width:200px;overflow-x: scroll;height:200px;overflow-y: scroll;',
uiOutput("plot"))) )
)
)
),
server = function(input, output) {
output$plot <- renderUI({
output$plot2 <- renderPlot(plot(cars))
plotOutput('plot2')
})
}
)
The default renderPlot(width="auto")
causes it to inherit the width from the default plotOutput(width="100%")
. This means the plot is drawn to the size of the div, which here you give to be 200px, therefore no overflow is required. Overflow will be active if you explicitly specify either the width of renderPlot(width=300)
or of plotOutput(width="300px")
(note the former is integer, latter is character).
shinyApp(
ui = fluidPage(
sidebarLayout(
sidebarPanel(
),
mainPanel(
column(6,(div(style='width:200px;overflow-x: scroll;height:200px;overflow-y: scroll;',
uiOutput("plot"))) )
)
)
),
server = function(input, output) {
output$plot <- renderUI({
output$plot2 <- renderPlot(plot(cars),width=300) # either will
plotOutput('plot2',width='300px') # work
})
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With