3

I'm creating a project where I'm hoping to embed an interactive histogram into an html page generated from an R Markdown document. Because of the costs associated with the number of interactive histograms and the potential volume of usage, Shiny is not a feasible approach for this project, so I'm attempting to embed an html widget for an interactive histogram that can be filtered using Crosstalk and Plotly. So far, I've been able to create a filterable histogram when using the group argument in ggplot(aes()) (reprex included below). Ultimately, I would like to use multiple variables to filter the histogram, which would cause problems if I'm using the group argument.

Is there a way that I can filter histograms using Crosstalk and Plotly without using the group argument?

Thanks!

library(crosstalk)
library(plotly)
library(reprex)

shared_mtcars <- SharedData$new(mtcars)
bscols(widths = c(3, NA),
       list(
         filter_checkbox("cyl", "Cylinders", shared_mtcars, ~cyl, inline = TRUE)
       ),
       plotly::ggplotly(shared_mtcars %>% 
                          ggplot(aes(x = mpg, group = factor(cyl))) + 
                          geom_histogram(fill = "pale green",
                                         color = "black") + 
                          theme(legend.position = "none"))
)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.