Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206255

Adding custom ActionButtons to popups in leaflet map within shiny app

$
0
0

I'm trying to build an app in R shiny where users can learn details about points on a map. When users click on a point, a popup shows some initial details and then an ActionButton (or ActionLink). When the user clicks on that ActionButton, an ObserveEvent reactive launches a modal dialog displaying more information about that point. I have the maps, ActionButtons, and modal dialogs in place. However, I can't figure out how to "assign" each ActionButton to its point/popup on the map. Is there a way to have each ActionButton inherit its ID from its respective point on the map and then pass that information to the ObserveEvent that launches the Modal Dialogue? Working example below:

library(shiny)
library(leaflet)
library(DT)

##Setup##
mapdata <- quakes
mapdata$latitude <- as.numeric(mapdata$lat)
mapdata$longitude <- as.numeric(mapdata$long)

ui <- fluidPage(
    leafletOutput("mymap")
)

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

    observeEvent(input$button_click, {
        showModal(modalDialog(
            title = "More Details",
            renderDataTable({
                df <- mapdata[1,]
                x <- as.data.frame(cbind(colnames(df),t(df)),row.names = F);colnames(x) <- c("Field","Value")
                x
            })
        ))
    })

    output$mymap <- renderLeaflet({
        leaflet(options = leafletOptions(maxZoom = 18)) %>% addTiles() %>%
            addMarkers(lat = ~ latitude, lng = ~ longitude,
                       data = mapdata,
                       popup= ~paste("<b>", mag, "</b></br>", actionLink(inputId = "modal", label = "View Details", onclick = 'Shiny.setInputValue(\"button_click\", this.id, {priority: \"event\"})')))
    })
}

###How can I assign an inputID to each actionLink that matches the id for that actionLink's point?

shinyApp(ui, server)

Viewing all articles
Browse latest Browse all 206255

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>