简体   繁体   中英

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"?

My attempt at UI code for the base shiny:

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:

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. 1.) I like how titlePanel and shinyWidgets::panel have their own area of space blocked out. AKA, I like how those options "look." 2.) I have no experience with absolutePanel and dont know how to center, change size, etc.

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:

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)

结果

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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