这是我第一次接触RShiny,遇到了一些问题。这个想法是添加两个选择按钮:第一个是纽约区域,然后选择社区。结果-在Airbnb上可用。但是,即使在图形部分之前,此代码也不起作用。
我有一个数据框,其中包括每个公寓的此类列:neighbourhood_groups(曼哈顿,布朗克斯等),邻里(纽约市5个行政区的221个),room_type,价格和空房情况。稍后,我想通过ggplot2软件包添加更多的数量图。
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("New-York City apartment offer on Airbnb "),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("area",
"Neighbourhood:",
choices = c('Manhattan', 'Brooklyn', 'Bronx', 'Queen', 'Staten Island')),
uiOutput("special"),
selectInput("room",
"Room Type:",
choices = unique(nyc_df$room_type)),
radioButtons("graph",
"Graph type:",
choices = c("Area plot", "Line plot"),
selected = "Area plot")
),
# Show a plot of the generated distribution
mainPanel(
)
)
)
a <- unique(nyc_df[nyc_df$neighbourhood_group == 'Brooklyn', 6])
b <- unique(nyc_df[nyc_df$neighbourhood_group == 'Manhattan', 6])
c <- unique(nyc_df[nyc_df$neighbourhood_group == 'Queen', 6])
d <- unique(nyc_df[nyc_df$neighbourhood_group == 'Staten Island', 6])
e <- unique(nyc_df[nyc_df$neighbourhood_group == 'Bronx', 6])
output$special <- renderUI({
switch(input$area,
"Brooklyn" = selectInput("nhd", "Neighbourhood:",
choices = a),
"Manhattan" = selectInput("nhd", "Neighbourhood:",
choices = b),
"Queens" = selectInput("nhd", "Neighbourhood:",
choices = c),
"Staten Island" = selectInput("nhd", "Neighbourhood:",
choices = d),
"Bronx" = selectInput("nhd", "Neighbourhood:",
choices = e))
})
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
area_data <- nyc_df[nyc_df$neighbourhood_group == req(input$area), ]
data <- area_data %>% filter(NHD == req(input$nhd),
Room == req(input$room))
barplot(data)
})
}
# Run the application
shinyApp(ui = ui, server = server)