3

How can I add a vertical y-axis scroll bar in a plotly line chart?

    library(plotly)
    
    x <- c(1:100)
    random_y <- rnorm(100, mean = 0)
    data <- data.frame(x, random_y)
    
    p <- plot_ly(data, x = ~x, y = ~random_y, type = 'scatter', mode = 'lines')

    p

I have a html code for scroll bar but i don't know how to integrate that code with plot

   Html <div style="overflow-y:scroll;height: 200px;">
Mario
  • 2,393
  • 2
  • 17
  • 37
Jerry Vfc
  • 75
  • 7

1 Answers1

3

Use the library htmltools. You can use HTML exactly as you've written it.

library(plotly)
library(htmltools)

x <- c(1:100)
random_y <- rnorm(100, mean = 0)
data <- data.frame(x, random_y)

p <- plot_ly(data, x = ~x, y = ~random_y, type = 'scatter', mode = 'lines')

p

# this combines the plot and your y scroll
browsable(div(style = "overflow-y: scroll; height: 200px;", p))
Kat
  • 15,669
  • 3
  • 18
  • 51