Show map in shiny

谁说我不能喝 提交于 2020-07-23 04:00:50

问题


I would like to generate the map in shiny (attached), however I am having trouble plotting the map from the code below. Could you take a look and help me solve it ??. The shapefile files can be downloaded from the following website: https://github.com/ropensci/stplanr/releases/download/0.6.1/Example.zip

If you do not have the sfnetworks package installed, please check this website: https://github.com/luukvdmeer/sfnetworks

Thank you very much!

library(shiny)
library(sf)
library(sfnetworks)
library(shinythemes)

roads = st_read("Example/Roads/Roads.shp", quiet = TRUE)
points = st_read("Example/Points/Points.shp", quiet = TRUE)
roads_trf = st_transform(roads, st_crs(points)) %>% 
  st_cast("LINESTRING")

net = as_sfnetwork(roads_trf, directed = FALSE) %>%
  activate("edges") %>%
  dplyr::mutate(weight = edge_length())

# routing 
p = sf::st_as_sf(data.frame(x = to[1], y = to[2]), coords = c("x", "y"), crs = sf::st_crs(net))
r = net %>%
  tidygraph::convert(to_spatial_shortest_paths, points[17, ], points[4, ])

# plot
plot(net)
plot <-plot(r, col = "blue", lwd = 5, add = TRUE)


ui <- bootstrapPage(
  navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
             "Cl", 
             tabPanel("Solution",
                      sidebarLayout(
                        sidebarPanel(
                         
                        ),
                        mainPanel(
                          tabsetPanel(      
                            tabPanel("Solution", (plotOutput(("Map"))))))
                        
    
           ))))

server <- function(input, output, session) {
  
  output$Map <- renderPlot({
})
}

shinyApp(ui = ui, server = server)


回答1:


 output$Map <- renderPlot({
    plot(net)
    plot(r, col = "blue", lwd = 5, add = TRUE)
    
    })


来源:https://stackoverflow.com/questions/62878163/show-map-in-shiny

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!