【问题标题】:Using scroll bars for big plots in R Shiny app在 R Shiny 应用程序中使用滚动条绘制大图
【发布时间】:2020-06-11 17:20:30
【问题描述】:

我想在 Shiny 应用程序中为绘图添加滚动条,但只有垂直滚动条出现,而水平滚动条不出现。我在此处附加了一个带有最少元素的小型闪亮应用程序来演示该问题。

cat("\014")
unlink(".RData")
rm(list=ls(all.names = TRUE))

  # A basic shiny app with a plotOutput
  shinyApp(
    ui = fluidPage(
      sidebarLayout(
        sidebarPanel(
        ),
        mainPanel(
          column(6,(div(style='width:200px;overflow-x: scroll;height:200px;overflow-y: scroll;',
                      uiOutput("plot"))) )

        )
      )
    ),
    server = function(input, output) {
      output$plot <- renderUI({
       output$plot2 <- renderPlot(plot(cars))
       plotOutput('plot2')
      })
    }
  )

【问题讨论】:

    标签: r plot shiny scrollbar horizontal-scrolling


    【解决方案1】:

    默认renderPlot(width="auto") 使其继承默认plotOutput(width="100%") 的宽度。这意味着绘图被绘制到 div 的大小,在这里你给定为 200px,因此不需要溢出。如果您明确指定renderPlot(width=300)plotOutput(width="300px") 的宽度(注意前者为整数,后者为字符),则溢出将处于活动状态。

    shinyApp(
      ui = fluidPage(
        sidebarLayout(
          sidebarPanel(
          ),
          mainPanel(
            column(6,(div(style='width:200px;overflow-x: scroll;height:200px;overflow-y: scroll;',
                          uiOutput("plot"))) )
            
          )
        )
      ),
      server = function(input, output) {
        output$plot <- renderUI({
          output$plot2 <- renderPlot(plot(cars),width=300) # either will
          plotOutput('plot2',width='300px')                # work
        })
      }
    )
    

    【讨论】:

    • 非常感谢。您的解决方案解决了我的问题。
    • @XiaoweiMa 太棒了!您能否将我的解决方案标记为已回答?
    • @stackoverflow.com/users/1639069/brooks-ambrose。抱歉,网站不允许我给你正面反馈:“声望低于 15 人的投票将被记录,但不要更改公开显示的帖子得分。”
    • @XiaoweiMa 您应该会在正面/负面反馈箭头下方看到一个复选标记图标,让您可以接受 Brooks 的回答作为解决方案。你不需要任何声望就能做到这一点。
    猜你喜欢
    • 1970-01-01
    • 2017-02-22
    • 2019-06-15
    • 2019-03-28
    • 1970-01-01
    • 2021-03-13
    • 2014-04-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多