R: не удается прочитать блестящие объекты Ошибка: чтение объектов из блестящего выходного объекта не допускается - PullRequest
0 голосов
/ 11 декабря 2019
genres <- c("Pop", "Rap")
bins <- c(0, 10, 20, 50, 100, 200, 500, 1000, Inf)
pal <- colorBin("Greens", domain = c(0,2000), bins = bins)

ui <- dashboardPage(
  skin = "green",
  dashboardHeader(title = "Concert Ticket Prices Spotify & Seat Geek"),
  dashboardSidebar(selectInput("genre", label = "Genre",choices = genres, selected = "Rap")),

  dashboardBody(

    fluidRow(box(width = 12,leafletOutput(outputId = "mymap"))),
    downloadButton('downloadData', 'Download Data Set (CSV)'),
    fluidRow(box(width = 12, dataTableOutput(outputId = "summary_table"))),
    fluidRow(textOutput(outputId = "n1")),
  )



)
server <- function(input, output, session){



  text <- reactive({input$genre})
  text2 <- reactive({text()})



  genre_shp <- Allgenre[Allgenre$genre == text2,]








  labels <- sprintf(
  "<strong>%s</strong><br/>Average Price: $%g <br/>%s </br> %s, %s <br/> %s ",
  genre_shp$Artist, genre_shp$`Avg Price`, genre_shp$Venue, genre_shp$City, genre_shp$name, genre_shp$`Data & Time`
) %>% lapply(htmltools::HTML)



  output$mymap <- renderLeaflet(
    leaflet(genre_shp) %>%
  setView(-96, 37.8, 4) %>%
  addProviderTiles("MapBox", options = providerTileOptions(
    id = "mapbox.light",
    accessToken = Sys.getenv('MAPBOX_ACCESS_TOKEN'))) %>%
  addPolygons(
    fillColor = ~pal(genre_shp$`Avg Price`),
    weight = 2,
    opacity = 1,
    color = "white",
    dashArray = "3",
    fillOpacity = 0.7,
    highlight = highlightOptions(
      weight = 5,
      color = "#666",
      dashArray = "",
      fillOpacity = 0.7,
      bringToFront = TRUE),
    label = labels,
    labelOptions = labelOptions(
      style = list("font-weight" = "normal", padding = "3px 8px"),
      textsize = "15px",
      direction = "auto")) %>%
  addLegend(pal = pal, 
            values = genre_shp$`Avg Price`, opacity = 0.7, title = NULL,
    position = "bottomright")

    )
  genres <- c("Pop", "Rap")
bins <- c(0, 10, 20, 50, 100, 200, 500, 1000, Inf)
pal <- colorBin("Greens", domain = c(0,2000), bins = bins)

ui <- dashboardPage(
  skin = "green",
  dashboardHeader(title = "Concert Ticket Prices Spotify & Seat Geek"),
  dashboardSidebar(selectInput("genre", label = "Genre",choices = genres, selected = "Rap")),

  dashboardBody(

    fluidRow(box(width = 12,leafletOutput(outputId = "mymap"))),
    downloadButton('downloadData', 'Download Data Set (CSV)'),
    fluidRow(box(width = 12, dataTableOutput(outputId = "summary_table"))),
    fluidRow(textOutput(outputId = "n1")),
  )



)
server <- function(input, output, session){



  text <- reactive({input$genre})
  text2 <- reactive({text()})



  genre_shp <- Allgenre[Allgenre$genre == text2,]








  labels <- sprintf(
  "<strong>%s</strong><br/>Average Price: $%g <br/>%s </br> %s, %s <br/> %s ",
  genre_shp$Artist, genre_shp$`Avg Price`, genre_shp$Venue, genre_shp$City, genre_shp$name, genre_shp$`Data & Time`
) %>% lapply(htmltools::HTML)



  output$mymap <- renderLeaflet(
    leaflet(genre_shp) %>%
  setView(-96, 37.8, 4) %>%
  addProviderTiles("MapBox", options = providerTileOptions(
    id = "mapbox.light",
    accessToken = Sys.getenv('MAPBOX_ACCESS_TOKEN'))) %>%
  addPolygons(
    fillColor = ~pal(genre_shp$`Avg Price`),
    weight = 2,
    opacity = 1,
    color = "white",
    dashArray = "3",
    fillOpacity = 0.7,
    highlight = highlightOptions(
      weight = 5,
      color = "#666",
      dashArray = "",
      fillOpacity = 0.7,
      bringToFront = TRUE),
    label = labels,
    labelOptions = labelOptions(
      style = list("font-weight" = "normal", padding = "3px 8px"),
      textsize = "15px",
      direction = "auto")) %>%
  addLegend(pal = pal, 
            values = genre_shp$`Avg Price`, opacity = 0.7, title = NULL,
    position = "bottomright")

    )

   output$summary_table <- renderDataTable(data.frame(genre_shp))



   output$downloadData <- downloadHandler(
    filename = function() { 
      paste('SelectedRows', '.csv', sep='')
      },
    content = function(file) {
      write.csv(genre_shp, file)
    }
    )




}
shinyApp(ui=ui, server = server)

Я пытаюсь создать панель мониторинга, которая обновляется с помощью выпадающего меню. У меня есть данные о концертах и ​​их стоимости. У меня есть большой набор данных, который нужно разделить для построения графика, так как я планирую строить по жанрам, используя карту США. Однако, когда я пытаюсь получить данные из входного $ жанра, мне не разрешают использовать выходные данные для фильтрации моего фрейма данных для построения графика. Любая помощь будет оценена. Спасибо вам всего наилучшего M

Ответы [ 2 ]

0 голосов
/ 11 декабря 2019

Это не пошло:

  text <- reactive({input$genre})
  text2 <- reactive({text()})

  genre_shp <- Allgenre[Allgenre$genre == text2,]

Первые две строки не обязательны. Третий вариант невозможен, поскольку text2 является реактивным значением. Просто сделайте:

genre_shp <- reactive(Allgenre[Allgenre$genre == input$genre,])

Затем используйте genre_shp() в качестве аргумента листовки.

0 голосов
/ 11 декабря 2019

Эта часть выглядит странно для меня

text <- reactive({input$genre})
text2 <- reactive({text()})

genre_shp <- Allgenre[Allgenre$genre == text2,]

Почему бы просто

output$mymap <- renderLeaflet( {
genre_shp <- Allgenre[Allgenre$genre == input$genre,]
leaflet(genre_shp)
})
...