bs4Dash
repository·master·Indexed 19 days ago
https://github.com/rinterface/bs4dashAn R package providing a Bootstrap 4-based dashboard interface for Shiny applications using the AdminLTE3 framework. It offers enhanced UI components and layouts, maintains compatibility with many shinydashboard function calls for easier migration, and includes a built-in gallery via bs4DashGallery().
What's inside bs4Dash
- bs4Dash is an R package that provides a Bootstrap 4-based dashboard interface for Shiny applications, utilizing the AdminLTE3 framework. It is designed to enhance the visual capabilities of standard Shiny dashboards.
Fix content resizing on card maximize/minimize
masterAdminLTE3's 'maximize' feature changes the dimensions of a box, but Shiny does not automatically know when to resize its internal content (like plots or tables) to fit the new size.
To resolve this, you must trigger the
shownevent within themaximizeandminimizeprototypes inadminlte.js. This tells Shiny to recalculate and resize the content. Additionally, ensure that anydelay()functions used during the transition are managed so that input bindings remain functional.// Inside maximize prototype $(this).trigger('shown'); // Inside minimize prototype $(this).trigger('shown');Install bs4Dash
masterYou can install
bs4Dashusing several methods depending on whether you want the stable CRAN version or the latest development versions.From CRAN (Stable)
Use the standard installation command for the stable release.
From r-universe (Latest Development)
Use this to get the latest development builds from the r-universe repository.
From GitHub (Latest Development)
Use
pakto install directly from the GitHub repository.# from CRAN install.packages("bs4Dash") # latest devel version from r-universe install.packages("bs4Dash", repos = c("cynkra.r-universe.dev", "cloud.r-project.org")) # latest devel version pak::pak("RinteRface/bs4Dash")Fix content visibility on card expand/collapse
masterWhen using cards that start in a collapsed state, Shiny might not automatically detect the change in visibility when the card is expanded. To fix this, you must trigger the appropriate Bootstrap collapse events within the
adminlte.jsprototypes so Shiny can react to the state change.- In the
collapseprototype: triggerhidden.bs.collapseon the parent. - In the
expandprototype: triggershown.bs.collapseon the parent.
// Inside collapse prototype _this._parent.trigger("hidden.bs.collapse"); // Inside expand prototype _this2._parent.trigger("shown.bs.collapse");- In the
Migrate from {shinydashboard} to {bs4Dash}
masterTransitioning from
{shinydashboard}to{bs4Dash}is straightforward becausebs4Dashmaintains compatibility with many existingshinydashboardfunction calls (likedashboardPage,dashboardHeader,dashboardSidebar,dashboardBody,fluidRow, andbox).To migrate, you primarily need to replace
library(shinydashboard)withlibrary(bs4Dash)in your application script.library(shiny) library(bs4Dash) ui <- dashboardPage( dashboardHeader(title = "Basic dashboard"), dashboardSidebar(), dashboardBody( fluidRow( box(plotOutput("plot1", height = 250)), box( title = "Controls", sliderInput("slider", "Number of observations:", 1, 100, 50) ) ) ) ) server <- function(input, output) { set.seed(122) histdata <- rnorm(500) output$plot1 <- renderPlot({ data <- histdata[seq_len(input$slider)] hist(data) }) } shinyApp(ui, server)Ensure shinyFiles compatibility in bs4Dash
masterBecause
shinyFilesis based on Bootstrap 3, it may conflict with the default AdminLTE3/bs4Dash CSS. To ensure proper modal rendering when usingshinyFiles, you may need to adjust the.modal-headerstyles. Specifically, avoid using flexbox properties on the.modal-headerif they cause layout issues, and instead use standard padding and border properties..modal-header { padding: 1rem; border-bottom: 1px solid #e9ecef; border-top-left-radius: 0.3rem; border-top-right-radius: 0.3rem; }Explore the bs4Dash Gallery
masterTo see examples of what you can build with
bs4Dash, you can launch the built-in gallery application using thebs4DashGallery()function.library(bs4Dash) bs4DashGallery()