2016-05-12 58 views
2

目标

嗨,我有两个数据集。我想通过使用radioButtonsshinydashboard中一次选择一个。为什么闪亮的仪表板加载时间过长?

问题

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

目前还不清楚你想用单选按钮做什么。您无法将数据集传递给选择选项。请看看http://shiny.rstudio.com/gallery/radio-buttons.html – Divi

+0

@Divi这个程序是不完整的。我想从两个数据集中选择一个,然后绘制其中的一部分。对于选择我使用'radioButtons' –

+0

你是什么意思“它不加载” - 什么不加载? – SymbolixAU

回答

4

我不知道你想绘制到底是什么,所以这里有一个例子:

单选框在ui.R会像:

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) 
}) 
+0

谢谢,我对这些选择感到困惑 –

+1

我假设你知道'plot'对象需要放在'dashboardBody()'中,你可以使用'fluidRow'和'box'来获得你想要的结果。 – Divi