在 r shiny 中使用动态存储桶列表时,Googleway 地图不会更新

Googleway map does not update when using a dynamic bucketlist in r shiny

提问人:Ward Greunke 提问时间:11/14/2023 更新时间:11/14/2023 访问量:31

问:

我正在构建一个 r 闪亮的应用程序,它使用可排序的遗愿清单和谷歌道路地图按州显示机场。首次运行时,用户可以将机场从一个遗愿清单拖到另一个遗愿清单,然后该机场就会显示在谷歌地图上。但是,当我更改状态时,存储桶列表会更新,但地图不会更新。当我尝试将项目从一个存储桶列表移动到另一个存储桶列表时,地图不会更新,并且仍然显示旧地图中的值。

library(shiny)
library(googleway)
library(sortable)
library(dplyr)


states<-c("CA","CA","CA","NY","NY","NY")
airport<-c("SFO","OAK","LAX","JFK","Spadero","KIUA")
lat<-c(37.615223,37.7156,33.9438,40.6446,40.8227,42.9069)
lon<-c(-122.38997,-122.2143,-118.4091,-73.7797,-72.7489,-77.3207)

airport_list<-data.frame(states,airport,lat,lon)
print("airport_list")
print(airport_list)


# ******************** UI **************************
ui <- fluidPage(
  titlePanel("Airport"),
  fluidRow(
    
    column(6,
           selectInput(inputId="chosen_state", label="Choose a state", choices=c("CA","NY"),selected="CA"),
           google_mapOutput(outputId = "myMap"),    
    ),
    column(6,
           
           uiOutput("bucket"),
           
    )
  ))

# ******************** Server **************************

server <- function(input, output,session){
  
  observeEvent(input$chosen_state,{
    places_list <- airport_list[airport_list$states == input$chosen_state, "airport"]
    print("places_list") 
    print(places_list) 
    output$bucket <- renderUI({bucket_list(header = "List of Airports",group_name = "bucket_list_container",orientation = "vertical",
                                           add_rank_list(text = "Show Airport",labels = places_list[1], input_id = "show_list"),
                                           add_rank_list(text = "Open Airports",labels = places_list,input_id = "open_list")
    )
      
    })
  })
  
  
  observeEvent(input$show_list,{
    
    trip_df <- airport_list[airport_list$airport %in% unlist(input$show_list), ]
    
    print("input$show_list")
    print(unlist(input$show_list))
    
    #Sort based on the order in the UI  
    trip_df <-trip_df[match(input$show_list, trip_df$airport), ]
    
    print("trip df")
    print(trip_df)   
    
    #I added a default value when the bucketlist first loads and that gets rid of grey box.
    output$myMap <- renderGoogle_map({
      google_map(data=trip_df,key = mapKey) %>%
        add_markers(lat="lat", lon="lon",label="airport")%>%
        add_polylines(lat="lat",lon="lon")
    })
    print("The map was updated")
  })
  
  
}

shinyApp(ui, server)

我试图通过在chosen_state observeEvent 中绘制一个空地图来重置地图,但这不起作用。

出于某种原因,更新存储桶列表后,地图渲染不起作用。output$map 块正在运行,因为我可以打印出“地图已更新”,但它没有更新。

r 闪亮 的 jquery-ui-sortable googleway

评论

0赞 SymbolixAU 11/14/2023
您的代码给出了一个错误:Error in : Static path must not have trailing slash.

答: 暂无答案