嗨,我有两个数据集。我想在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)
没有错误消息。我做错了什么?
答案 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)
})