R/Shiny+Leafet로 클릭 좌표값 저장

5597 단어 RleafletShiny
reactiveValues 를 사용하면 된다.
library(shiny)
library(leaflet)

ui <- fluidPage(
  leafletOutput(outputId="map", height="500"),
  tableOutput(outputId="rv")
)

server <- function(input, output, session){
  output$map <- renderLeaflet(expr={
    leaflet() %>%
      addTiles() %>%
      setView(lng=135, lat=35, zoom=9)
  })

  rv <- reactiveValues(lat=NULL, lng=NULL)
  observeEvent(
    eventExpr=input$map_click,
    handlerExpr={
      rv$lat <- append(rv$lat, input$map_click$lat)
      rv$lng <- append(rv$lng, input$map_click$lng)
    }
  )

  output$rv <- renderTable(expr={
    data.frame(rv$lat, rv$lng)
  })
}

shinyApp(ui, server)

좋은 웹페이지 즐겨찾기