Hello,
I have a small problem strange for me. When i click on a country map to figure out the caracteristics of a town, instead of displaying only the town i click on, it displays often
other town and i don't understand why? I would also like to have more than one information when i click.
Can anyone please tell me what's wrong with my code:
observeEvent(input$Map_marker_click, {
click <- input$Map_marker_click
output$table <- renderTable({
subset(data(), select = c(population, sqmeter, nb_cars, oil_stations))[unique(data()$population) == click$id, ]
Thanks a lot,
This may take several iterations for me to understand your issue.
The first thing I would try is to insert a print statement after each operation to see what you variables contain.
Also, is this a single expression or two?
subset(data(), select = c(population, sqmeter, nb_cars, oil_stations))[unique(data()$population) == click$id, ]
The renderTable() function isn't closed as I see no "})", so that leaves me puzzled.
observeEvent(input$Map_marker_click, {
click <- input$Map_marker_click
print(click)
output$table <- renderTable({
subset(data(), select = c(population, sqmeter, nb_cars, oil_stations))[unique(data()$population) == click$id, ]
Thank you for response and sorry about the iterations. Perhaps something is missing in my code, good point let me do a print and come back.
ps. i believe a single expression i just click on popups in a map and get a print of the details like population etc. the problem is that sometimes on click induces two or more prints which not logical to me.
Hello
I insert print function and i only get few information ("latitude", "longitude", "id", and one i don't understand ".nonce").
It did not help me understand why some times when i click one one popup i get two printed results including the one i click on it and the other one appears with no reason.
My concern is that I only want the print of the popup i click on it.
Below is the code:
observeEvent(input$Map_marker_click, {
click <- input$Map_marker_click
output$table <- renderTable({
subset(data(), select = c(population, sqmeter, nb_cars, oil_stations))[unique(data()$population) == click$id, ]
}) })
Thank you.
Posting the output exactly as you see it is more useful that describing it.
Thank you for responding. In fact the output is just the output of the click with figures below population, sqmeter, nb_cars, and oil_stations that appears twice. I mean i don't see it as informative. Perhaps should i change the structure of the code.
If you had thought the output to be informative you would have acted on it already. It's just possible that it is informative, but you don't recognize it.
Exactly, thanks for response. The output does not contain more information about the problem, instead of displaying once the four items, it displays twice but not the same information. For example, when i click on a popup, it displays the content of the popup and below the content of of another popup that i did not click on. So I try after your comment about the ouput to see the link on both popup, like correlation among figures etc, but nothing appear except that latitude and longitude are very close. I believe something in my code is wrong, i used e.g. unique(variable) to extract only one but perhaps, data is more complex.
What library are you using to generate your map? I ask because I made a Shiny app where I created interactive maps by converting ggplot maps to plotly maps using ggplotly. This resulted in two popups when hovering over a marker. I got rid of the unwanted one by modifying the plotly object's properties. Here's an example of one part of my code:
# Remove default tooltips
recent_sale_plot$x$data[[2]]$hoverinfo <- "none"
recent_sale_plot$x$data[[3]]$hoverinfo <- "none"
recent_sale_plot$x$data[[4]]$hoverinfo <- "none"
recent_sale_plot$x$data[[5]]$hoverinfo <- "none"
# Add account numbers to the layer with tooltips
recent_sale_plot$x$data[[6]]$customdata <- joined_tbl$accounttype or paste code here
Here's a link to that app. If any of this looks familiar, I may be able to help.
Emerald Gardens
Thanks a lot. I'm not sure i understand your code but let me see more deeply.
I use leaflet() in shiny for mapping : leafletProxy('Map')%>%addMarkers(lng = click$lng, lat = click$lat)
ps. i change my laptop which could induce delay.
My suggestion reflected in the earlier link isn't relevant to you as it doesn't involve leaflet.
Here's a link to a different Shiny app that I posted last week. It uses leaflet.
Sarasota Medical Providers
This is a code chunk where I set a marker in a leaflet map. Here is the entire observeEvent() function that places a marker when a row in the data table is clicked.
# When a row in the provider_listings_table is clicked, this assigns
# the row's values to the set of objects and uses these values to
# display a marker and a pop-up with the provider's information.
observeEvent(input$provider_listings_table_row_last_clicked, {
req(input$provider_listings_table_row_last_clicked)
clicked_row_index_listings <- input$provider_listings_table_row_last_clicked
clicked_display_data <- provider_listings_filtered()[clicked_row_index_listings, ]
clicked_provider_name <- clicked_display_data$provider
clicked_provider_id <- clicked_display_data$NPI
selected_provider_sf_row <- HHS_NPPES_sarasota_npi_data_tbl %>% filter(NPI == clicked_provider_id)
clicked_lon <- sf::st_coordinates(selected_provider_sf_row)[1]
clicked_lat <- sf::st_coordinates(selected_provider_sf_row)[2]
leafletProxy("provider_map") %>%
clearMarkers() %>%
addMarkers(lng = clicked_lon,
lat = clicked_lat,
popup = paste("<b>",
clicked_provider_name, "</b><br>",
"Field: ", clicked_display_data$field, "<br>",
"Specialty: ", clicked_display_data$specialization, "<br>",
"Address: ", clicked_display_data$street, "<br>",
"Phone: ", clicked_display_data$phone)) %>%
setView(lng = clicked_lon, lat = clicked_lat, zoom = 15)
shinyjs::runjs("var panel = document.getElementById('provider_sliding_panel');
var map = document.getElementById('provider_map');
if (panel && map) { panel.scrollTo({ top: map.offsetTop, behavior: 'smooth' }); }")
})
See if any of this looks similar to what you are doing.
You are very kind. Thanks a lot. It will be helpful to rewrite my code.
I will let you know with my new laptop.
All the best,