r - R闪亮渲染:找不到对象“输出”
问题描述
这是我在 RShiny 的第一次体验,但遇到了一些问题。这个想法是添加两个选择按钮:第一个是纽约地区,然后你选择社区。结果——在 Airbnb 上可用。但是,即使在图形部分之前,此代码也不起作用。
我有一个数据框,其中包含每个公寓的此类列:neighbourhood_groups(曼哈顿、布朗克斯等)、社区(纽约市 5 个行政区的 221 个)、房间类型、价格和可用性。稍后我想通过 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)
解决方案
推荐阅读
- r - 将变量除以数据框中的其他变量
- javafx - JavaFX:从内部照亮对象
- javascript - 使用 vuetify.js 创建表和子表——不知道从哪里开始
- c# - 将分隔字符串转换为 Expando 对象
- php - 多文件输入和表单验证?
- python - 将条目与分桶表阈值进行比较,因为它们被填充到 SQL 数据库中
- python - 在 Beautiful Soup 中定位没有标签的文本元素
- javascript - 如何使用ajax在laravel中几秒钟后自动存储数据?
- python - pandas 数据框以 csv 格式导出到 zip 文件中
- ios - 用户完成输入并按回车后,如何使用 textField 在 UIAlertController 中触发 UIAlertAction?[IOS-斯威夫特]