无法读取闪亮对象错误:不允许从闪亮输出对象读取对象

问题描述 投票:0回答:2
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)
   

我正在尝试构建一个使用下拉菜单更新的仪表板。我拥有的数据是将要举行的音乐会及其费用。我有一个大型数据集需要拆分以进行绘图,因为我计划使用美国地图按流派进行绘图。但是,当我尝试从 input$genre 获取数据时,我不允许利用输出来过滤数据框以进行绘图。

r shiny r-leaflet
2个回答
0
投票

这部分对我来说看起来很奇怪

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)
})

0
投票

这是不行的:

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

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

前两行不是必需的。 第三种是不可能的,因为

text2
是无功值。 只要这样做:

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

然后使用

genre_shp()
作为传单参数。

© www.soinside.com 2019 - 2024. All rights reserved.