2016-05-12 104 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