I've been trying to develop a few web apps using Mapdeck in R that revolve around building site maps. Right now I'm trying to develop an app that will return a value on click.
My question, with the below sample, what exactly does Mapdeck return on a click event? I thought it was whatever was assigned to the 'id' value, however the stuff I'm getting back seems to be a nested data that isn't related to my data frame input. In the below example I'd like it to return the 'Point_ID' value for each site.
# ################################################################################################
# ################################################################################################
# # Sec 1a. Needed Libaries & Input Files
library(shiny)
library(shinydashboard)
library(mapdeck)
library(dplyr)
Map_DF <- data.frame("Point_ID" = c("A1", "B1", "C3"),
"Latitude" = c(38.05, 39.08, 40.05),
"Longitude" = c(-107.00, -107.05, -108.00),
"PointUse" = c("farm", "house", "well"),
"info" = c("A1 38.05 -107.00 farm",
"B1 39.08 -107.05 house",
"C3 40.05 -108.00 well"))
################################################################################################
################################################################################################
#UI
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
fluidRow(mapdeckOutput(outputId = 'mapA')),
fluidRow(htmlOutput("textOutA"))
)
)
################################################################################################
################################################################################################
server <- function(input, output) {
##The MapDeck Token
key <- '## put your own token here ##'
set_token(key) ## set your access token
### The Map
output$mapA <- renderMapdeck({
mapdeck() %>%
add_scatterplot(
data = Map_DF,
lat = "Latitude",
lon = "Longitude",
id = 'Point_ID',
tooltip = "info",
radius = 10000,
# radius_min_pixels = 3,
auto_highlight = TRUE,
)
})
##Click Event, return text
observe({
click <- input$mapA_scatterplot_click
if(is.null(click)) {
output$textOutA <- renderUI({
str1 <- paste("Nothing...")
HTML(paste(str1))
})
} else {
output$textOutA <- renderUI({
str1 <- paste(click)
HTML(paste(str1))
})
}
})
}
################################################################################################
################################################################################################
shinyApp(ui = ui, server = server)