简体   繁体   English

滚动时如何保持titlePanel(或shinyWidgets::panel)固定?

[英]How to keep titlePanel (or shinyWidgets::panel) fixed while scrolling?

I am interested in keeping a panel of action buttons FIXED at the top of the page while I am scrolling.我有兴趣在滚动时将操作按钮面板固定在页面顶部。 How do I do this for either (or both) the base shiny "titlePanel" or the "shinyWidgets::panel"?我如何为基础闪亮的“titlePanel”或“shinyWidgets::panel”中的一个(或两者)做到这一点?

My attempt at UI code for the base shiny:我尝试为基础闪亮的 UI 代码:

ui <- shinyUI(fluidPage(
  titlePanel(style = "position:fixed;width:inherit;",
    fluidRow(
      column(12, align="center",
             actionButton("rmd1", "RMD1"),
             actionButton("rmd2", "RMD2")
      )
    ))
  ,uiOutput("uioutput")

))

My attempt at UI code using shinyWidgets::panel:我尝试使用 ShinyWidgets::panel 编写 UI 代码:

ui <- shinyUI(fluidPage(
  shinyWidgets::panel(style = "position:fixed;width:inherit;",
    fluidRow(
      column(12, align="center",
             actionButton("rmd1", "RMD1"),
             actionButton("rmd2", "RMD2")
      )
    ))
  ,uiOutput("uioutput")

))

PS I am avoiding using "absolutePanel" for a few reasons. PS 我避免使用“absolutePanel”有几个原因。 1.) I like how titlePanel and shinyWidgets::panel have their own area of space blocked out. 1.) 我喜欢 titlePanel 和 ShinyWidgets::panel 有自己的空间区域。 AKA, I like how those options "look." AKA,我喜欢这些选项的“外观”。 2.) I have no experience with absolutePanel and dont know how to center, change size, etc. 2.) 我没有绝对面板的经验,不知道如何居中,改变大小等。

That being said, if a solution exists with absolutePanel that makes it look like one of the other two options, I am not opposed to trying it.话虽如此,如果绝对面板存在一个解决方案,使它看起来像其他两个选项之一,我不反对尝试它。

You were almost there.你快到了。 You can simply wrap your titlePanel in a div to style it:您可以简单地将titlePanel包装在一个div以对其进行样式设置:

library(shiny)

ui <- shinyUI(fluidPage(
  div(titlePanel(fluidRow(
               column(12, align="center",
                      actionButton("rmd1", "RMD1"),
                      actionButton("rmd2", "RMD2")
               )
             )), style = "position:fixed; width:inherit;"),
  uiOutput("uioutput", height = "2000px")

))

server <- function(input, output, session) {
  output$uioutput <- renderUI({tagList(HTML(rep("...<br>", 100)), hr())})
}

shinyApp(ui, server)

结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM