【问题标题】:Why shiny dashboard is taking too long to load?为什么闪亮的仪表板加载时间过长?
【发布时间】:2016-05-12 21:44:12
【问题描述】:

目标

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

问题

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)

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

【问题讨论】:

  • 不清楚你想用单选按钮做什么。您不能将数据集传递给选择选项。请看shiny.rstudio.com/gallery/radio-buttons.html
  • @Divi 这个应用程序还不完整。我想从 2 个数据集中选择一个,然后绘制其中的一部分。对于选择,我使用radioButtons
  • “它不加载”是什么意思 - 什么不加载?
  • 您可能不想在单选按钮中包含庞大的数据集。只需放置 2 个文本,然后根据所选文本,选择数据集
  • 是的,正如@HubertL 所说——不要使用list("US-101" = df10151, ...——df10151 是你的数据集。您可能需要list("US-101" = 1, ...,然后使用switchif 选择您正在绘制的数据集

标签: r shiny shinydashboard


【解决方案1】:

我不确定你到底想画什么,所以这里是一个例子:

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

【讨论】:

  • 谢谢。我对这些选择感到困惑。
  • 我假设您知道plot 对象需要放在dashboardBody() 中。您可以使用fluidRowbox 来获得您想要的结果。
猜你喜欢
  • 2018-04-30
  • 1970-01-01
  • 2015-04-22
  • 1970-01-01
  • 2019-02-12
  • 2016-12-05
  • 1970-01-01
  • 2020-10-08
  • 2016-05-02
相关资源
最近更新 更多