Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Locking R shiny dashboard sidebar (shinydashboard)

Tags:

r

shiny

I'm getting stuck while building a Shiny Dashboard in R (using the shinydashboard package). I want to lock my sidebar so that it does not scroll while I look through the content of my tabs, but I'm not sure how to pull this off.

As an example, the following block of code will create a long-scrolling dashboard. It would be nice to lock the sidebar so that you can still see the menu tabs whilst scrolling through the obscenely-long data table.

library(ggplot2)  ## for mpg dataset
library(shinydashboard)

## ui
ui <- dashboardPage(
  dashboardHeader(title="MPG Data"), 
  dashboardSidebar(sidebarMenu(menuItem("MPG", tabName="mpg"))), 
  dashboardBody(tabItems(tabItem(tabName="mpg", fluidRow(tableOutput("mpgTable"))))))

## server
server <- function(input, output) {
  output$mpgTable <- renderTable({mpg})
}

## launch dashboard 
shinyApp(ui, server)
like image 227
Hip Hop Physician Avatar asked Jun 23 '15 21:06

Hip Hop Physician


People also ask

How do I hide the sidebar in R shiny?

d. To hide the text on collapse, Shiny needs to know that the sidebar is collapsed. To do so, we will add a Shiny Input that will respond to a click on the collapse button. '. sidebar-toggle' is the button class.

What is Shinydashboard?

Background: Shiny and HTML The shinydashboard package provides a set of functions designed to create HTML that will generate a dashboard. If you copy the UI code for a dashboard page (above) and paste into the R console, it will print out HTML for the dashboard.


1 Answers

You should just add the style = "position:fixed; overflow: visible" at the ui sidebar.

library(ggplot2)  ## for mpg dataset
library(shinydashboard)

## ui
ui <- dashboardPage(
  dashboardHeader(title="MPG Data"), 
  dashboardSidebar(
    sidebarMenu(style = "position: fixed; overflow: visible;",
      menuItem("MPG", tabName="mpg"))), 
  dashboardBody(
    tabItems(
      tabItem(tabName="mpg", 
       fluidRow(tableOutput("mpgTable"))))))

## server
server <- function(input, output) {
  output$mpgTable <- renderTable({mpg})
}

## launch dashboard 
shinyApp(ui, server)
like image 148
Eduardo Schindler Avatar answered Nov 01 '22 22:11

Eduardo Schindler