Just getting started with my first Shiny app, so bear with me... I have a simple Shiny app where I display a ggplot, brush within it, and then show the average value of the brushed points. I use a sliderInput to control the xlim range of the plot.
ggplot displays some blank space on either side of the plot, outside the xlim range. Brushing the plot (I'm using direction=x) allows you to select outside the range of the points that are shown. It appears that when I average my brushedPoints, it averages all the points that are within the brushed range, including points that are not shown in the plot. This could be counterintuitive to my users. Any thoughts on controlling this?
library(shiny)
library(tidyverse)
df <- mtcars
ui <- fluidPage(
plotOutput('plot',brush=brushOpts(id="plot_brush",direction="x")),
fluidRow(
column(6,
sliderInput("range", label="Range", min = 0,
max = max(df$wt), value = c(0, max(df$wt)))
),
column(6,
tableOutput("brush_info")
)
)
)
server <- function(input, output) {
output$plot <- renderPlot({
ggplot(df,aes(x=wt,y=mpg)) +
geom_point() +
xlim(input$range)
})
output$brush_info <- renderTable({
brushedPoints(df,input$plot_brush) %>% summarize_at(vars(mpg),mean)
})
}
shinyApp(ui = ui, server = server)