r - Popups not working with leaflet & shiny -
i having trouble getting popups work in shiny app using leaflet package. application uses shinydashboard package well. copied code superzip example. example works fine locally, not within app. below of server.r
file.
any clue cause problem?
thanks!
library(shiny) library(leaflet) function(input, output, session) { mapp <- createleafletmap(session, "map") # filter dataset visit_data_f <- reactive({ s <- as.posixct(input$period[1], format = "%y-%m-%d") e <- as.posixct(input$period[2], format = "%y-%m-%d") hour(s) <- 23; minute(s) <- 59; second(s) <- 59; hour(e) <- 23; minute(e) <- 59; second(e) <- 59; d <- filter(visit_data, started_on >= s, started_on <= e) if (input$district != "tous") { d <- filter(d, district == input$district) } d }) geo_data <- reactive({ data <- visit_data_f() data$site_code <- factor(data$site_code) # sync lag d <- data.frame(sync_lag(data, "site_code")) d <- cbind(rownames(d), d) colnames(d) <- c("site_code", "sync_lag") d <- mutate(d, sync_lag = round(as.numeric(sync_lag), 2)) d <- arrange(d, site_code) # consults consults <- data.frame(table(data$site_code)) colnames(consults) <- c("site_code", "n_consults") consults <- arrange(consults, site_code) d <- mutate(d, n_consults = consults$n_consults) # coordinates d <- merge(d, locations_data, by.x = "site_code", by.y = "site_code") d <- filter(d, !is.na(latitude)) d$id <- seq(1:nrow(d)) d }) session$onflushed(once = true, function() { paintobs <- observe({ data <- geo_data() mapp$clearshapes() mapp$clearmarkers() if (input$geo_data == "position") { mapp$addmarker(data$latitude, data$longitude) } else if (input$geo_data == "n_consults") { radius <- data$n_consults mapp$addcircle(data$latitude, data$longitude, radius * 5, data$id, list(stroke = f, fill = t, fillopacity = 0.4)) } else { radius <- data$sync_lag mapp$addcircle(data$latitude, data$longitude, radius * 150, data$id, list(stroke = f, fill = t, fillopacity = 0.4)) } }) session$onsessionended(paintobs$suspend) }) showinfopopup <- function(id, lat, lng) { content <- paste("csps :", id) mapp$showpopup(lat, lng, content, id) } clickobs <- observe({ mapp$clearpopups() event <- input$mapp_shape_click if (is.null(event)) { print("-- null") return() } isolate({ showinfopopup(event$id, event$lat, event$lng) }) }) session$onsessionended(clickobs$suspend) }