R Блестящий рендеринг: объект «Вывод» не найден - PullRequest
0 голосов
/ 07 мая 2020

Это мой первый опыт работы в Ршинах и возникли проблемы. Идея состоит в том, чтобы добавить две кнопки выбора: первая предназначена для района Нью-Йорка, затем вы выбираете районы. В результате - доступный на Airbnb. Однако этот код не работает даже до графической части.

У меня есть фрейм данных, который состоит из таких столбцов для каждой квартиры: Neighbourhood_groups (Манхэттен, Бронкс и т. Д. c), District (221 в 5 районах Нью-Йорка C), room_type, price and availability . Позже я хотел бы добавить больше количественных графиков пакетом 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)

...