使sidebarPanel自动滚动,使mainPanel变亮 [英] Make sidebarPanel autoscroll with mainPanel in shiny

查看:115
本文介绍了使sidebarPanel自动滚动,使mainPanel变亮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个闪亮的sidebarLayout,可以在发生溢出时在mainPanel中滚动。 sidebarPanel的位置保持固定,从而在您向下滚动mainPanel时消失。但是,我希望它与mainPanel一起滚动 ,这样用户无需再次向上滚动即可更改设置。我该怎么做?

I made a sidebarLayout in shiny which allows for scrolling in the mainPanel in case of overflow. The sidebarPanel's position remains fixed, such that it disappears as you scroll down the mainPanel. However, I'd like it to scroll with the mainPanel, so that the user doesn't need to scroll up again to change settings. How do I do this?

基本设置:

ui = fluidPage(

  tags$style(type='text/css', 'body { overflow-y: scroll; }'),

  titlePanel(
    # ...
  ),

  sidebarLayout(

    sidebarPanel(
      # ...
      width = 3),

    mainPanel(
      # ...

      width = 9 )

  ))

server = function(input,output,session) {

  # ...

}

shinyApp(ui=ui, server=server)


推荐答案

您可以添加 style = position:fixed; width :inherit; 到您的 sidebarPanel ,但是您将为元素放宽填充,宽度将恰好是1/4(25%)页面的大小,例如,如果要在侧边栏面板和主面板之间留出更多空间,则输入22%。

You can add style = "position:fixed;width:inherit;" to your sidebarPanel, but you will loose padding for your element, and the width will be exactly 1/4 (25%) of your page, put 22% for example if you want more space between sidebar panel and main panel.

example:

library("shiny")

ui <- fluidPage(

  titlePanel(
    "Fixed sidebar panel"
  ),

  sidebarLayout(

    sidebarPanel(
      style = "position:fixed;width:inherit;",
      "Inputs",
      width = 3),


    mainPanel(

      lapply(
        X = 1:20,
        FUN = function(i) {
          plotOutput(outputId = paste("plot", i, sep = "-"))
        }
      ),

      width = 9 )

  ))

server <- function(input, output, session) {

  lapply(
    X = 1:20,
    FUN = function(i) {
      output[[paste("plot", i, sep = "-")]] <- renderPlot({plot(rnorm(10))})
    }
  )

}

shinyApp(ui = ui, server = server)

这篇关于使sidebarPanel自动滚动,使mainPanel变亮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆