为什么闪亮的仪表板需要很长时间才能加载?

时间:2016-05-12 21:44:13

标签: r shiny shinydashboard

目的

嗨,我有两个数据集。我想在radioButtons中使用shinydashboard一次选择一个。

问题

app.R文件中,我首先加载两个数据集(大小为71 Mb和103 Mb)。以下代码有效,只需几秒钟即可加载应用程序:

工作代码:

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)

但是当我添加radioButtons时,它需要永远而且无法加载:

代码失败:

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)

没有错误消息。我做错了什么?

1 个答案:

答案 0 :(得分:4)

我不确定你想要绘制什么,所以这是一个例子:

ui.R中的Radiobutton将起作用:

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

对于server.R,您需要以下内容:

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