Search code examples
shinyplotly

How to remove graph showing in the range slider?


I am developing a R Shiny dashboard and making use of the range slider, however I do not like the repeat of the chart showing in the slider - how do I remove this?

I have just sent the link from the plotly info page to show what I mean:

chart

I have created this:

xaxis_plots[["rangeslider"]] <- list(range="week_ending", visible = TRUE, thickness = 0.05, bgcolor = "#ECEBF3")

However, it still shows the chart inside when I add it to plotly code.


Solution

  • Here is a way. We plot two times the series. One invisibly and we add the range slider for this series. Then we plot the second series on a second x-axis.

    library(plotly)
    
    plot_ly() %>%
      add_lines(x = time(USAccDeaths), y = USAccDeaths, xaxis = "x2") %>%
      add_lines(x = time(USAccDeaths), y = USAccDeaths, visible = FALSE) %>%
      layout(
          xaxis = list(rangeslider = list(visible = TRUE)),
          xaxis2 = list(matches = "x", overlaying = "x")
      )
    

    enter image description here