【发布时间】:2016-04-12 23:37:07
【问题描述】:
嗨,我对 Shiny 很陌生。我正在尝试为我的用户创建两个交互式 selectInputs 以在表中显示数据。这是我的代码的样子: ui.R
library(shiny)
shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("var",
label = "Country",
choices = c("ALL", "A2", "AE")),
selectInput("plat",
label = "Platform",
choices = c("ALL", "Android", "IPhonePlayer"))
)
),
mainPanel(
tableOutput(
"view"))
)
))
服务器.R
library(shiny)
library(ggplot2)
library(dplyr)
df <- readRDS("data/df.rds")
shinyServer(function(input, output) {
datasetInput <- reactive({
switch(input$var,
"ALL" = df,
"A2" = df %>% filter(country == "A2"),
"AE" = df %>% filter(country == "AE"))
switch(input$plat,
"ALL" = df,
"Android" = df %>% filter(platform == "Android"),
"IPhonePlayer" = df %>% filter(platform == "IPhonePlayer"))
})
output$view <- renderTable({head(datasetInput())})
})
当我运行代码时,只有平台上的选择可以正常工作,而对于国家/地区,我进行选择时没有任何反应。关于我在这里犯了什么愚蠢的错误有什么想法吗?提前非常感谢您!
【问题讨论】: