I have a shiny app with long vertical pages that require scrolling from the user. The dashboard has a sidebarpanel with filters. That sidebar has a fixed position so that the user can always see what filters they have selected. Unfortunately, the sidebar itself gets cut off by the bottom of the screen. I'd like to implement some javascript so that the sidebar is "sticky" when scrolling as in this other stackoverflow post or this example. How would I do this? I'm new to adding javascript to shiny apps. Thanks!
See the reproducible example below.
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(shinythemes)
library(plotly)
library(htmltools)
library(shinyjs)
######################
#UI###################
######################
ui <- navbarPage("Example", theme = shinytheme("flatly"),
header = tagList(
useShinydashboard(),
useShinyjs()
),
tabPanel("Tab",
fluidRow(column(12,
h1("Text"),
br(),
br(),
h4("Text"),
p("Use the filters on the left to explore data"))),
hr(),
fluidRow(sidebarPanel(style = "position: fixed; overflow: auto; width:24%;margin-bottom:50px","Inputs",
width = 3,
h4("Filters"),
helpText("Chose parameters to narrow down the dataset."),
pickerInput(inputId = "a", label = "a", choices = c(seq(1,5,1)), selected = 1, multiple = TRUE),
pickerInput(inputId = "b", label = "b", choices = c(seq(1,5,1)), selected = 1, multiple = TRUE),
pickerInput(inputId = "c", label = "c", choices = c(seq(1,5,1)), selected = 1, multiple = TRUE),
pickerInput(inputId = "d", label = "d", choices = c(seq(1,5,1)), selected = 1, multiple = TRUE),
helpText("Test.")
),
mainPanel(fluidRow(infoBoxOutput("total")),
plotlyOutput("stuff1"),
h4("About this Chart"),
htmlOutput("stuff2"),
hr(),
br(),
br(),
plotlyOutput("stuff3"),
h4("About this Chart"),
htmlOutput("stuff4"),
hr(),
br(),
br(),
fluidRow(plotlyOutput("stuff4"),plotlyOutput("stuff5")),
h4("About this Chart"),
htmlOutput("stuff6"),
hr(),
br(),
br(),
fluidRow(plotlyOutput("stuff7"),plotlyOutput("stuff8")),
h4("About this Chart"),
htmlOutput("stuff9"),
hr())
)))
######################
#SERVER###############
######################
server <- function(input, output, session) {
}
shinyApp(ui, server)