### Install JavaScript Packages with Yarn Source: https://github.com/rstudio/shinydashboard/blob/main/tools/README.md Installs all necessary JavaScript packages for shinydashboard development using yarn. This command should be run in the 'tools' directory after Node.js and yarn are installed. It reads the package.json file to determine which packages to install. ```bash yarn ``` -------------------------------- ### Install Grunt CLI Globally Source: https://github.com/rstudio/shinydashboard/blob/main/tools/README.md Installs the Grunt command-line interface globally on the system. This allows the 'grunt' command to be run from any directory. Note that this does not install the Grunt task runner itself, which is managed by yarn within the project. ```bash sudo yarn global add grunt-cli ``` -------------------------------- ### Complete Dashboard Application Example in R Source: https://context7.com/rstudio/shinydashboard/llms.txt A comprehensive example of a shinydashboard application demonstrating various components including headers, sidebars, bodies, value boxes, info boxes, plots, tables, and reactive controls. This serves as a full-scale template for building feature-rich dashboards. ```r library(shiny) library(shinydashboard) ui <- dashboardPage( dashboardHeader( title = "Complete Dashboard", dropdownMenu( type = "notifications", notificationItem( text = "5 new users today", icon = icon("users") ) ) ), dashboardSidebar( sidebarMenu( id = "tabs", menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")), menuItem("Analytics", tabName = "analytics", icon = icon("chart-line")) ) ), dashboardBody( tabItems( tabItem( tabName = "dashboard", fluidRow( valueBoxOutput("ordersBox"), valueBoxOutput("revenueBox"), infoBoxOutput("progressBox") ), fluidRow( box( title = "Monthly Revenue", status = "primary", solidHeader = TRUE, collapsible = TRUE, plotOutput("revenuePlot", height = 250) ), box( title = "Controls", status = "warning", sliderInput("months", "Months:", 1, 12, 6), selectInput("category", "Category:", choices = c("Sales", "Marketing", "Operations") ) ) ) ), tabItem( tabName = "analytics", h2("Analytics Dashboard"), box( title = "Performance Metrics", width = 12, tableOutput("metricsTable") ) ) ) ), skin = "blue" ) server <- function(input, output, session) { output$ordersBox <- renderValueBox({ valueBox( value = 1240, subtitle = "Total Orders", icon = icon("shopping-cart"), color = "aqua" ) }) output$revenueBox <- renderValueBox({ valueBox( value = "$45,600", subtitle = "Revenue", icon = icon("dollar-sign"), color = "green" ) }) output$progressBox <- renderInfoBox({ infoBox( title = "Progress", value = paste0(input$months * 8, "%"), icon = icon("tasks"), color = "yellow" ) }) output$revenuePlot <- renderPlot({ data <- cumsum(rnorm(input$months, mean = 1000, sd = 200)) plot(data, type = "l", col = "blue", lwd = 2, xlab = "Month", ylab = "Revenue", main = paste("Revenue -", input$category)) }) output$metricsTable <- renderTable({ data.frame( Metric = c("Conversion Rate", "Avg. Order Value", "Customer Retention"), Value = c("3.2%", "$125", "78%") ) }) } shinyApp(ui, server) ``` -------------------------------- ### Run Grunt Watch Task Source: https://github.com/rstudio/shinydashboard/blob/main/tools/README.md Starts the Grunt watch task, which monitors project files for changes and automatically runs specified tasks (like minification and linting) as necessary. This is useful for continuous development. ```bash grunt watch ``` -------------------------------- ### Create a Dashboard Header with Dropdown Menus Source: https://context7.com/rstudio/shinydashboard/llms.txt Illustrates how to construct the `dashboardHeader` component, which forms the top navigation bar. It includes examples of adding dropdown menus for messages, notifications, and tasks, enhancing user interaction. ```r header <- dashboardHeader( title = "Dashboard Demo", dropdownMenu( type = "messages", badgeStatus = "success", messageItem( from = "Support Team", message = "This is the content of a message.", time = "5 mins" ), messageItem( from = "New User", message = "Can I get some help?", time = "Today" ) ), dropdownMenu( type = "notifications", badgeStatus = "warning", notificationItem( icon = icon("users"), status = "info", text = "5 new members joined today" ), notificationItem( icon = icon("warning"), status = "danger", text = "Resource usage near limit." ) ), dropdownMenu( type = "tasks", badgeStatus = "danger", taskItem(value = 20, color = "aqua", text = "Refactor code"), taskItem(value = 80, color = "red", text = "Write documentation") ) ) ``` -------------------------------- ### R Package Installation Failure Due to Matrix Dependency Source: https://github.com/rstudio/shinydashboard/blob/main/revdep/failures.md This snippet illustrates a common R package installation error where the build process fails because a required package ('Matrix') has an incompatible version. The error message indicates that a newer version of 'Matrix' is needed than what is currently installed. This occurs during the byte-compilation and lazy-loading stage. ```R * installing *source* package ‘AovBay’ ... ** package ‘AovBay’ successfully unpacked and MD5 sums checked ** using staged installation ** libs using C++ compiler: ‘g++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0’ using C++17 g++ -std=gnu++17 -I"/opt/R/4.3.1/lib/R/include" -DNDEBUG -I"../inst/include" -I"/usr/local/lib/R/site-library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error -DUSE_STANC3 -D_HAS_AUTO_PTR_ETC=0 -I'/usr/local/lib/R/site-library/BH/include' -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppEigen/include' -I'/usr/local/lib/R/site-library/RcppParallel/include' -I'/usr/local/lib/R/site-library/rstan/include' -I'/usr/local/lib/R/site-library/StanHeaders/include' -I/usr/local/include -I'/usr/local/lib/R/site-library/RcppParallel/include' -D_REENTRANT -DSTAN_THREADS -fpic -g -O2 -c RcppExports.cpp -o RcppExports.o In file included from /usr/local/lib/R/site-library/RcppEigen/include/Eigen/Core:205, ... ** data *** moving datasets to lazyload DB ** inst ** byte-compile and prepare package for lazy loading Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : namespace ‘Matrix’ 1.5-4.1 is being loaded, but >= 1.6.0 is required Calls: ... namespaceImportFrom -> asNamespace -> loadNamespace Execution halted ERROR: lazy loading failed for package ‘AovBay’ * removing ‘/tmp/workdir/AovBay/new/AovBay.Rcheck/AovBay’ ``` ```R * installing *source* package ‘SeuratExplorer’ ... ** package ‘SeuratExplorer’ successfully unpacked and MD5 sums checked ** using staged installation ** R ** inst ** byte-compile and prepare package for lazy loading Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : namespace ‘Matrix’ 1.5-4.1 is already loaded, but >= 1.6.4 is required Calls: ... namespaceImportFrom -> asNamespace -> loadNamespace Execution halted ERROR: lazy loading failed for package ‘SeuratExplorer’ * removing ‘/tmp/workdir/SeuratExplorer/new/SeuratExplorer.Rcheck/SeuratExplorer’ ``` -------------------------------- ### R Package Installation Error: Missing Dependency 'lordif' Source: https://github.com/rstudio/shinydashboard/blob/main/revdep/failures.md This snippet shows an error during R package installation where a required package, 'lordif', is not available. This indicates that the dependency specified in the package's DESCRIPTION file could not be found in the available package repositories. ```R * checking package dependencies ... ERROR Package required but not available: ‘lordif’ See section ‘The DESCRIPTION file’ in the ‘Writing R Extensions’ manual. * DONE Status: 1 ERROR ``` ```R * checking package dependencies ... ERROR Package required but not available: ‘lordif’ See section ‘The DESCRIPTION file’ in the ‘Writing R Extensions’ manual. * DONE Status: 1 ERROR ``` -------------------------------- ### Add a New JavaScript Package with Yarn Source: https://github.com/rstudio/shinydashboard/blob/main/tools/README.md Adds a new development package to the shinydashboard project. This command updates both the package.json dependencies and the yarn.lock file. After adding, other developers should run 'yarn' to install the new package. ```bash yarn add --dev [packagename] ``` -------------------------------- ### R Package Installation Error: Matrix Version Conflict Source: https://github.com/rstudio/shinydashboard/blob/main/revdep/failures.md This snippet illustrates an error encountered during the installation of R packages where a loaded 'Matrix' namespace version is incompatible with the required version. This typically occurs when one package depends on a newer version of 'Matrix' than what is currently loaded in the R session. ```R * installing *source* package ‘SeuratExplorer’ ... ** package ‘SeuratExplorer’ successfully unpacked and MD5 sums checked ** using staged installation ** R ** inst ** byte-compile and prepare package for lazy loading Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : namespace ‘Matrix’ 1.5-4.1 is already loaded, but >= 1.6.4 is required Calls: ... namespaceImportFrom -> asNamespace -> loadNamespace Execution halted ERROR: lazy loading failed for package ‘SeuratExplorer’ * removing ‘/tmp/workdir/SeuratExplorer/old/SeuratExplorer.Rcheck/SeuratExplorer’ ``` ```R * installing *source* package ‘shinyTempSignal’ ... ** package ‘shinyTempSignal’ successfully unpacked and MD5 sums checked ** using staged installation ** R ** inst ** byte-compile and prepare package for lazy loading Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : namespace ‘Matrix’ 1.5-4.1 is already loaded, but >= 1.6.0 is required Calls: ... namespaceImportFrom -> asNamespace -> loadNamespace Execution halted ERROR: lazy loading failed for package ‘shinyTempSignal’ * removing ‘/tmp/workdir/shinyTempSignal/new/shinyTempSignal.Rcheck/shinyTempSignal’ ``` ```R * installing *source* package ‘shinyTempSignal’ ... ** package ‘shinyTempSignal’ successfully unpacked and MD5 sums checked ** using staged installation ** R ** inst ** byte-compile and prepare package for lazy loading Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : namespace ‘Matrix’ 1.5-4.1 is already loaded, but >= 1.6.0 is required Calls: ... namespaceImportFrom -> asNamespace -> loadNamespace Execution halted ERROR: lazy loading failed for package ‘shinyTempSignal’ * removing ‘/tmp/workdir/shinyTempSignal/old/shinyTempSignal.Rcheck/shinyTempSignal’ ``` -------------------------------- ### Create a Basic Dashboard Page with shinydashboard Source: https://context7.com/rstudio/shinydashboard/llms.txt Demonstrates how to create the main dashboard page structure using `dashboardPage`, combining `dashboardHeader`, `dashboardSidebar`, and `dashboardBody`. This function sets up the overall layout for a Shiny dashboard. ```r library(shiny) library(shinydashboard) ui <- dashboardPage( dashboardHeader(title = "Sales Dashboard"), dashboardSidebar( sidebarMenu( menuItem("Overview", tabName = "overview", icon = icon("dashboard")), menuItem("Reports", tabName = "reports", icon = icon("file")) ) ), dashboardBody( tabItems( tabItem(tabName = "overview", h2("Overview Page")), tabItem(tabName = "reports", h2("Reports Page")) ) ), title = "Sales Dashboard", skin = "blue" ) server <- function(input, output) { } shinyApp(ui, server) ``` -------------------------------- ### Dynamically Render Value Boxes and Info Boxes in R Source: https://context7.com/rstudio/shinydashboard/llms.txt Illustrates how to create dynamically updating value boxes and info boxes using renderValueBox and infoBoxOutput. The server function reacts to input events (like button clicks) to update the box values and content. Requires shinyApp to run. ```r ui <- dashboardPage( dashboardHeader(title = "Dynamic Boxes"), dashboardSidebar(), dashboardBody( fluidRow( box(width = 2, actionButton("count", "Count")), valueBoxOutput("vbox", width = 4), infoBoxOutput("ibox", width = 4) ) ) ) server <- function(input, output) { output$vbox <- renderValueBox({ valueBox( value = input$count, subtitle = "Button Clicks", icon = icon("hand-pointer"), color = "blue" ) }) output$ibox <- renderInfoBox({ infoBox( title = "Current Value", value = input$count * 10, icon = icon("calculator"), color = "green", fill = TRUE ) }) } shinyApp(ui, server) ``` -------------------------------- ### Create a Dashboard Sidebar with Navigation and Search Source: https://context7.com/rstudio/shinydashboard/llms.txt Shows how to build the `dashboardSidebar`, which constitutes the left-hand navigation panel. This includes adding user panels, search forms, and a menu structure with sub-items and badges. ```r sidebar <- dashboardSidebar( sidebarUserPanel( name = "John Doe", subtitle = a(href = "#", icon("circle", class = "text-success"), "Online"), image = "user.png" ), sidebarSearchForm( textId = "searchText", buttonId = "searchButton", label = "Search..." ), sidebarMenu( id = "tabs", menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")), menuItem( "Widgets", tabName = "widgets", icon = icon("th"), badgeLabel = "new", badgeColor = "green" ), menuItem( "Charts", icon = icon("bar-chart-o"), menuSubItem("Sub-item 1", tabName = "subitem1"), menuSubItem("Sub-item 2", tabName = "subitem2") ) ) ) ``` -------------------------------- ### Create Dynamic Dropdown Menus in R Source: https://context7.com/rstudio/shinydashboard/llms.txt Demonstrates creating dynamic dropdown menus for messages or notifications using dropdownMenuOutput and renderMenu. The menu content can be generated based on data and reactive inputs. Requires shinyApp to run. ```r messageData <- data.frame( from = c("Administrator", "New User", "Support"), message = c( "Sales are steady this month.", "How do I register?", "The new server is ready." ), stringsAsFactors = FALSE ) ui <- dashboardPage( dashboardHeader( title = "Dynamic Menus", dropdownMenuOutput("messageMenu") ), dashboardSidebar(), dashboardBody( fluidRow( box( title = "Controls", sliderInput("slider", "Number of observations:", 1, 100, 50) ) ) ) ) server <- function(input, output) { output$messageMenu <- renderMenu({ msgs <- apply(messageData, 1, function(row) { messageItem( from = row[["from"]], message = paste(row[["message"]], input$slider) ) }) dropdownMenu(type = "messages", .list = msgs) }) } shinyApp(ui, server) ``` -------------------------------- ### Run Default Grunt Tasks Source: https://github.com/rstudio/shinydashboard/blob/main/tools/README.md Executes all default Grunt tasks defined in the Gruntfile, typically including minification and linting of JavaScript code. This command should be run from within the 'tools' directory. ```bash grunt ``` -------------------------------- ### Dynamically Render Sidebar Menus in R Source: https://context7.com/rstudio/shinydashboard/llms.txt Shows how to dynamically generate sidebar menus using sidebarMenuOutput and renderMenu. This allows the menu structure to change based on application state or user interactions. Requires shinyApp to run. ```r ui <- dashboardPage( dashboardHeader(title = "Dynamic Sidebar"), dashboardSidebar( sidebarMenuOutput("menu") ), dashboardBody() ) server <- function(input, output) { output$menu <- renderMenu({ sidebarMenu( menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")), menuItem("Settings", tabName = "settings", icon = icon("gear")), menuItem("Menu item", icon = icon("calendar")) ) }) } shinyApp(ui, server) ``` -------------------------------- ### Display Key Metrics with Value Boxes Source: https://context7.com/rstudio/shinydashboard/llms.txt Shows how to use `valueBox` within `dashboardBody` to present prominent numerical data. Each `valueBox` can display a value, subtitle, icon, color, and an optional hyperlink, ideal for summarizing key performance indicators. ```r dashboardBody( fluidRow( valueBox( value = 150, subtitle = "New Orders", icon = icon("credit-card"), color = "blue", width = 4, href = "http://example.com/orders" ), valueBox( value = "60%", subtitle = "Approval Rating", icon = icon("line-chart"), color = "green", width = 4 ), valueBox( value = 1200, subtitle = "Total Revenue", icon = icon("dollar"), color = "yellow", width = 4 ) ) ) ``` -------------------------------- ### Create Content Boxes for Layout and Controls Source: https://context7.com/rstudio/shinydashboard/llms.txt Demonstrates the use of the `box` component within `dashboardBody` to organize content. `box` allows for titles, status indicators, collapsing functionality, and dynamic width adjustments, suitable for plots and input controls. ```r dashboardBody( fluidRow( box( title = "Histogram", status = "primary", solidHeader = TRUE, collapsible = TRUE, width = 6, plotOutput("plot", height = 250) ), box( title = "Controls", status = "warning", width = 6, sliderInput("slider", "Number of observations:", 1, 100, 50) ) ), fluidRow( box( title = "Status Summary", background = "green", width = 4, textOutput("status") ), box( title = "Collapsed Box", status = "danger", solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE, width = 8, "This box starts collapsed" ) ) ) ``` -------------------------------- ### Organize Content into Tabs with tabItems in R Source: https://context7.com/rstudio/shinydashboard/llms.txt Demonstrates how to use tabItems and tabItem to create tabbed content within the dashboard body. Each tabItem corresponds to a specific tab, and its content is displayed when that tab is selected. This is typically controlled by menu items in the sidebar. ```r body <- dashboardBody( tabItems( tabItem( tabName = "dashboard", h2("Dashboard Content"), fluidRow( valueBox(150, "New Orders", icon = icon("shopping-cart")), valueBox("53%", "Progress", icon = icon("list") ) ), tabItem( tabName = "widgets", h2("Widgets Content"), box( title = "Widget Box", status = "primary", "Widget content goes here" ) ), tabItem( tabName = "reports", h2("Reports Content"), plotOutput("reportPlot") ) ) ) ``` -------------------------------- ### Upgrade All JavaScript Packages with Yarn Source: https://github.com/rstudio/shinydashboard/blob/main/tools/README.md Upgrades all project dependencies to their latest allowed versions based on the version ranges specified in package.json. This command will recreate the yarn.lock file. It respects semantic versioning rules defined by operators like '~' and '^'. ```bash yarn upgrade ``` -------------------------------- ### Display Statistics with Info Boxes in R Source: https://context7.com/rstudio/shinydashboard/llms.txt Demonstrates how to use the infoBox function to display statistics with icons and subtitles. It supports customization of title, value, subtitle, icon, color, width, and optional links. The 'fill' argument controls whether the infoBox has a filled background. ```r dashboardBody( fluidRow( infoBox( title = "Orders", value = 1410, subtitle = "80% of target", icon = icon("credit-card"), color = "aqua", width = 4, fill = FALSE ), infoBox( title = "Progress", value = "65%", icon = icon("users"), color = "purple", width = 4, fill = TRUE ), infoBox( title = "Approval", value = "92%", icon = icon("thumbs-up"), color = "green", width = 4, href = "http://example.com/details" ) ) ) ``` -------------------------------- ### Create Tabbed Containers with tabBox in R Source: https://context7.com/rstudio/shinydashboard/llms.txt Shows how to use the tabBox function to create containers with tabs for organizing different views. It allows setting a title, ID, width, height, and can include multiple tabPanel elements. The 'side' argument controls the placement of the tabs (e.g., 'right'). ```r dashboardBody( fluidRow( tabBox( title = "Analysis", id = "tabset1", width = 6, height = "250px", tabPanel("Tab1", plotOutput("plot1")), tabPanel("Tab2", tableOutput("table1")) ), tabBox( side = "right", width = 6, selected = "Settings", tabPanel("Overview", "Overview content"), tabPanel("Settings", "Settings content") ) ) ) ``` -------------------------------- ### Update Tab Items in shinydashboard with R Source: https://context7.com/rstudio/shinydashboard/llms.txt Demonstrates how to programmatically switch between tabs in a shinydashboard application from the server-side. This is useful for triggering tab changes based on user actions or application logic. It utilizes the `updateTabItems` function. ```r ui <- dashboardPage( dashboardHeader(title = "Tab Switching"), dashboardSidebar( sidebarMenu( id = "tabs", menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")), menuItem("Widgets", tabName = "widgets", icon = icon("th")) ), actionButton("switchtab", "Switch Tab") ), dashboardBody( tabItems( tabItem(tabName = "dashboard", h2("Dashboard tab content")), tabItem(tabName = "widgets", h2("Widgets tab content") ) ) ) ) server <- function(input, output, session) { observeEvent(input$switchtab, { newtab <- switch(input$tabs, "dashboard" = "widgets", "widgets" = "dashboard" ) updateTabItems(session, "tabs", newtab) }) } shinyApp(ui, server) ``` -------------------------------- ### Upgrade a Specific JavaScript Package with Yarn Source: https://github.com/rstudio/shinydashboard/blob/main/tools/README.md Upgrades a single, specified package to its latest tagged version. This can potentially update the package across major versions, unlike 'yarn upgrade' which adheres to specified version ranges. ```bash yarn upgrade [package] ``` -------------------------------- ### Handle Empty Shiny Outputs in Sidebar Animations (JavaScript) Source: https://github.com/rstudio/shinydashboard/blob/main/srcjs/AdminLTE/README-shiny-mods.md This JavaScript code snippet is designed to be inserted into the event listener for sidebar menu item clicks. It checks for empty Shiny outputs within the clicked menu item and inserts a line break if none exists. This ensures that the `slideDown()` animation appears reasonable even when outputs are initially empty. It relies on jQuery selectors. ```javascript var shinyOutput = checkElement.find('.shiny-bound-output'); if (shinyOutput.length !== 0 && shinyOutput.first().html().length === 0) { shinyOutput.first().html('
'); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.