umair durrani
umair durrani

Reputation: 6199

Why shiny dashboard is taking too long to load?

Objective

Hi, I have two datasets. I want to select one at a time by using radioButtons in shinydashboard.

Problem

In the app.R file, I first load the two data sets (71 Mb and 103 Mb in size). The following code works and only takes few seconds for app to load:

Working Code:

library(shiny)
library(dplyr)
library(shinydashboard)

# Global
df10151 <- read.csv("Data/df1015.csv", header = TRUE)
df8051 <- read.csv("Data/df805.csv", header = TRUE)

# UI
ui <- dashboardPage(
  dashboardHeader(title = "Driving States"),
  dashboardSidebar(
     sliderInput("fid", "Frame ID:",
                min = 0, max = 50, value = 3, step = 0.1
    )))

# Server
server <- function(input, output, session) {
 

}

shinyApp(ui, server)

But when I add the radioButtons, it takes forever and doesn't load:

Failing Code:

library(shiny)
    library(dplyr)
    library(shinydashboard)
    
    # Global
    df10151 <- read.csv("Data/df1015.csv", header = TRUE)
    df8051 <- read.csv("Data/df805.csv", header = TRUE)
    
    # UI
    ui <- dashboardPage(
      dashboardHeader(title = "Driving States"),
      dashboardSidebar(
        radioButtons("radio", label = h3("Select the Dataset (first 5 minutes)"),
                 choices = list("US-101" = df10151, "I-80" = df8051), 
                 selected = NULL),         

        sliderInput("fid", "Frame ID:",
                    min = 0, max = 50, value = 3, step = 0.1
        )))
    
    # Server
    server <- function(input, output, session) {
     
    
    }
    
    shinyApp(ui, server)

There is no error message. What am I doing wrong?

Upvotes: 2

Views: 1477

Answers (1)

Divi
Divi

Reputation: 1634

I am not sure what exactly you would like to plot, so here is an example:

Radiobutton in ui.R will work like:

radioButtons("radio", label = h3("Select the Dataset (first 5 minutes)"),
                 choices = c("US-101" = 1, "I-80" = 2), 
                 selected = 1)

For server.R you need something like:

output$plot = renderPlot({ 
       switch(input$radio,
       `1` = hist(df10151$Var),
       `2` = hist(df8051$Var)
})

Upvotes: 4

Related Questions