In Shiny, I select an x-axis range by brushing a plot, as in the MWE below:
library(shiny)
library(ggplot2)
library(cowplot)
library(shinydashboard)
test_ui <- function(id){
ns <- NS(id)
brush_options <- brushOpts(id = ns("brush"), fill = "#99CCFF", stroke = "#003366", opacity = 0.25,
delay = 1, delayType = "debounce", clip = TRUE,
direction = "x", resetOnNew = TRUE)
tagList(
plotOutput(outputId = ns("plot"), brush = brush_options, height=600, width=1600)
)
}
test_server <- function(id){
moduleServer(id, function(input, output, session){
ns <- session$ns
output$plot <- renderPlot({
ggplot(mtcars, aes(x = mpg, y = drat)) + geom_point()
})
})
}
demoApp <- function() {
ui <- fluidPage(
test_ui("demo")
)
server <- function(input, output, session) {
test_server("demo")
}
shinyApp(ui, server)
}
demoApp()
which produces:
However, now I have a very wide plot that I place inside a box to allow for x-axis scrolling to visualize it. Like this:
tagList(
box(style='width:600px;overflow-x:scroll;',
plotOutput(outputId = ns("plot"), brush = brush_options, height=600, width=1600)
)
)
But when trying the brush selection on that, this happens:
Is it possible to have these 2 things work in agreement (brush selection of a scrollable plot)? The ideal would be to have the scroll bar move as you do the brush selection.