【发布时间】:2019-08-25 21:24:24
【问题描述】:
我正在尝试根据省列和城市列对数据框进行子集化。在闪亮中,我想让用户使用 selectInput UI 选择省份然后选择城市。
以下是数据框的外观。
列InfoTemp[2]是城市,InfoTemp[3]是省份。
数据集很大,它们实际上有很多层次。
归根结底,这是我计划去的一个情节(对于一个城市)。
这是目前为止的代码,没有做任何事情......
服务器.R
library(shiny)
shinyServer(function(input, output) {
#MeanTemp
load("CanadianMeanTemp.Rdata")
province = input$provinces
city = input$cities
output$distPlot <- renderPlot({
MeanTemp_province = MeanTemp[grep(c(province), MeanTemp$`InfoTemp[3]`),]
MeanTemp_city = MeanTemp_province[grep(c(city), MeanTemp$`InfoTemp[2]`),]
plot(MeanTemp_city$Year, MeanTemp_city$Annual, type = "l")
lines(supsmu(MeanTemp_city$Year, MeanTemp_city$Annual), col = 2)
})
})
ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("Temperature"),
sidebarLayout(
sidebarPanel(
selectInput('provinces', 'Province', choices = levels(MeanTemp$`InfoTemp[3]`)),
conditionalPanel(
condition = "input.provinces == true",
selectInput('cities', 'City', choices = levels(MeanTemp_province$`InfoTemp[2]`))
)
),
mainPanel(
plotOutput("distPlot")
)
)
))
【问题讨论】:
标签: r shiny selectinput