0

Quick note: I have also posted this question on the R Studio Community.

I am trying to modify a plotly slider to make it a rangeslider similar to the one here: enter image description here.

The problem with the rangeslider() function is that instead of a rangeslider like the one in the image it produces one that is essentially a subplot of the main plot:

dat<- data.frame(y=rnorm(366, mean=100, sd=50),
                 x=seq(as.Date("2020-01-01"), as.Date("2020-12-31"), by="days"))
p1<- dat %>% 
  ggplot(aes(x=x, y=y)) +
  geom_col() +
  theme_minimal() +
  xlab("") + ylab("") 
ggplotly(p1, tooltip="x", dynamicTicks = TRUE) %>% rangeslider()

enter image description here.

I have managed to get a slider more similar to the one I want in style using frame = in ggplot's aesthetics, however the resulting slider only selects one value at a time instead of a range of them:

dat<- data.frame(y=rnorm(366, mean=100, sd=50),
                 x=seq(as.Date("2020-01-01"), as.Date("2020-12-31"), by="days"))
p1<- dat %>% 
  ggplot(aes(x=x, y=y, frame=as.character(x))) +
  geom_col(position="dodge2") +
  theme_minimal() +
  xlab("") + ylab("") 
ggplotly(p1, tooltip="x")

enter image description here.

Is it possible to create a rangeslider in the style I want with plotly?. I would be hugely thankful for any advice on how to solve this issue.

cholo.trem
  • 314
  • 2
  • 9

1 Answers1

0

Unfortunately, the built-in Plotly sliders only have one "handle" and so cannot express a range.

nicolaskruchten
  • 26,384
  • 8
  • 83
  • 101
  • I have devised a kind of solution using crosstalk's filter_slider() (https://rpubs.com/LucasT/715872), however this does not zoom in to the graph when the range is selected in the same way range_slider() does. – cholo.trem Jan 23 '21 at 10:01
  • And how about connectin the rangeslider form Shiny to a plotly plot? Is that doable? See my question: https://stackoverflow.com/questions/70392086/connect-rangeslider-r-shiny-to-plotly-plot – H. berg Dec 17 '21 at 12:47