【发布时间】:2019-08-21 23:02:23
【问题描述】:
我正在尝试为我的项目构建一个 Rshiny。我正在尝试包含 2 个输入, First Input 是一个下拉列表,其中包含从 1 月到 12 月的月份。 第二个输入可以是下拉列表或任何允许我选择多个项目的内容。第二个输入项是-“Assault”,“Theft”,“Burgary”等。 用户只能从第一个输入中选择一个项目,从第二个输入中选择多个项目。 所以基本上,如果我从第一个输入中选择 Jan 并从第二个输入中选择“Assault”,“Theft”,则应该显示一个条形图,描述 Assault 和 Theft In jan 的数量。
输入数据框如下所示
PrimaryType Month count
Assault Jan 25
Burglary Jan 30
Tresspass Feb 23
Assault Feb 12
Burglary Feb 34
ui <- fluidPage(
titlePanel(div(HTML("<em> Crime Rate in Chichago </em>"))),
tabsetPanel(
tabPanel(" Frequency of Crime ",
sidebarLayout(
sidebarPanel(
#First Input#
selectInput(inputId = "Month",
label = " Choose a Month",
choices = unique(crime$Month))),
#Second input#
selectInput(inputId = "Crime",
label = " Choose among Crime",
choices = unique(crime$`Primary Type`),multiple =
TRUE)),
#Output#
mainPanel = (plotOutput("view")
)
)
)
)
#Shiny app -Server#
server <- function(input, output) {
output$view <- renderPlot({
Monthfilter <- a[a$Month==input$Month,]
crimefilter <- Monthfilter[Monthfilter$`Primary Type` %in% input$Crime,]
ggplot(crimefilter, aes(`Primary Type`,c))+geom_bar(stat="identity")
})
}
#Shinyapp#
shinyApp(ui = ui, server = server)
我想要一个包含多种主要犯罪类型的特定月份的条形图
【问题讨论】:
标签: r shiny shinydashboard shiny-reactivity