Issues between inputs and plot output
嗨,
我正在测试一个基本的ShinyApp,在那里我可以生成按地理和服务类型细分的商业服务图 .
我的想法是希望用户使用三个下拉菜单输入,每个输入取决于之前的选择,对数据进行子集化,然后在ggplot中输出 .
但是,我在将输入连接到绘图输出时遇到问题(见下文) . 输入在选择时工作正常和反应,但我无法弄清楚如何将其与情节联系起来,我感觉我没有使用正确的数据源(但不知道如何确保它是) . 此外,我不熟悉如何添加第三个过滤器(用于“服务”),因为我不知道如何首先链接我的数据源 .
对不起,这可能很简单,但一些帮助将非常感激 .
UI
#Data
Test
Geography1 = c("Region","Local Authority","County"...),
Geography2 = c("North West","Aldershot","Cheshire"...),
Service = c("Shop","Cafe","Library"...),
Overall_rating = c("Awesome","Good","Fantatstic"...),
Locations = c(4000, 1300, 1700...)
)
#SHINY APP
ui
titlePanel("Tool"),
sidebarLayout(
sidebarPanel(
uiOutput("geography1"),
uiOutput("geography2"),
uiOutput("service")),
mainPanel(
plotOutput("plot", height = "400px"))
)
)
Server
server
output$geography1 = renderUI({
selectInput(inputId = "geog1",
label = "Geography 1:",
choices = as.character(unique(Test$Geography1)),
selected = "Region")
})
output$geography2 = renderUI({
datasub
selectInput(inputId = "geog2",
label = "Geography2:",
choices = unique(datasub),
selected = unique(datasub)[1])
})
output$service = renderUI({
datasub2
selectInput(inputId = "service",
label = "Service type:",
choices = unique(...),
selected = unique(...)[1])
})
output$plot = renderPlot({
ggplot(datasub2(),aes(x = Overall_rating, y = Locations, fill= Overall_rating))+
geom_bar(stat = "identity")
})
}
shinyApp(ui, server)