最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

shiny - Add vertical scrollbar to barplot plotly R - Stack Overflow

programmeradmin5浏览0评论

I would like to add a scrollbar to a barplot of plotly. I tried using a div with a style to add a scrollbar. Unfortunately, this doesn't work. Here is a simple reproducible example:

library(plotly)
library(shiny)

ui <- page_fluid(
  div(
    style = "overflow-y: scroll; position: relative",
    plotlyOutput(outputId = "plot")
  )
)

server <- function(input, output, ...) {
  output$plot <- renderPlotly({ 
    df <- data.frame(
      x = 1:26,
      y = LETTERS
    )
    fig <- plot_ly(data = df, x = ~x, y = ~y, type = 'bar', orientation = 'h')
    fig
  }) 
}

shinyApp(ui, server)

Output:

As you can see in the output there is no scrollbar added. So I was wondering how we can add a scrollbar to a plotly graph to scroll through multiple bars so every labels will be visible?

I would like to add a scrollbar to a barplot of plotly. I tried using a div with a style to add a scrollbar. Unfortunately, this doesn't work. Here is a simple reproducible example:

library(plotly)
library(shiny)

ui <- page_fluid(
  div(
    style = "overflow-y: scroll; position: relative",
    plotlyOutput(outputId = "plot")
  )
)

server <- function(input, output, ...) {
  output$plot <- renderPlotly({ 
    df <- data.frame(
      x = 1:26,
      y = LETTERS
    )
    fig <- plot_ly(data = df, x = ~x, y = ~y, type = 'bar', orientation = 'h')
    fig
  }) 
}

shinyApp(ui, server)

Output:

As you can see in the output there is no scrollbar added. So I was wondering how we can add a scrollbar to a plotly graph to scroll through multiple bars so every labels will be visible?

Share Improve this question asked Mar 25 at 13:18 QuintenQuinten 41.8k11 gold badges51 silver badges108 bronze badges Recognized by R Language Collective
Add a comment  | 

1 Answer 1

Reset to default 2

You're almost there, but you need to specify some heights because otherwise the outer div will just expand to whatever height the plot is. e.g.:

  div(
    style = "overflow-y: scroll; position: relative; height: 400px",
    plotlyOutput(outputId = "plot", height = "800px")
  )
发布评论

评论列表(0)

  1. 暂无评论