Hi there,
first post in here, so apologies if I fail certain forum rules.
I'd like to detect the bin selection in a ggplot histogram using a horizontal brush event. This is my (simplified) program:
library(shiny)
library(ggplot2)
library(dplyrr)
ui = fluidPage(
plotOutput("iris_hist", click = "plot_click", brush = brushOpts("plot_brush", resetOnNew = T, direction = "x"))
)
server = function(input, output, session) {
observeEvent(input$plot_brush, {
selectedRange = brushedPoints(streamData(), iris)
## errors !!!
})
output$iris_hist = renderPlot({
iris %>% ggplot(aes(Sepal.Width)) + geom_histogram()
})
}
shinyApp(ui, server)
It starts fine, but after selecting a range in the histogram it fails with the following error
Warning: Error in brushedPoints: brushedPoints requires a brush object with xmin, xmax, ymin, and ymax.
74: stop
73: brushedPoints
72: observeEventHandler [d:/documents/arbeitsmappe/snippets/R/shiny/realttime_dashhboard/scratches/brushOptsHist.R#12]
1: shiny::runApp
What am I doing wrong? Is there an alternative to brushPoints for ggplot histograms, or could I instrument it differently to provide the selected bins?
Best regards,
Holger