I am using R leaflet and I added a custom button to the map using 'addEasyButton'. I have trawled any conceivable source and can not find a suggested way to create a mouse-hover label to pop up for my new button. The default buttons (Zoom ' ' and '-') as well a re-center map, all have labels popping up when you hover with the mouse over them. I inspected the html on chrome trying to find the difference between the standard buttons and my new button with no success.
Under the 'server' function of my Shiny app, I have:
output$map <- renderLeaflet({
leaflet(options = leafletOptions(preferCanvas = TRUE)) %>%
# Center map on chosen feature
setView(lng = Centroid[1], lat = Centroid[2], zoom = 10) %>%
# Add OSM basemap
addProviderTiles(providers$OpenStreetMap.HOT, group = "Street Map",
options = providerTileOptions(updateWhenIdle = TRUE)) %>%
addEasyButtonBar(easyButton(id = 'Search',
icon = span(class = "star", HTML("⨁ id='Search' aria-label='Search'" )),
onClick = JS("function(btn, map){var mapsearch = {btn: 'btn1', map: 'map1', nonce: Math.random(), id: 'Search'};
Shiny.onInputChange('jsValue', mapsearch);}"))) %>%
addResetMapButton() %>%
addMouseCoordinates()
})
This works well enough and I managed to make my button do the things I want it to do. The challenge is just communicating that to the user by creating a label to pop up when you hover over the button with the mouse. I use the shinyJS library, the shiny library and the leaflet collection of libraries.
It is such a small thing but so incredibly important to have. Any help would be greatly appreciated. I have to re-emphasise that this question relates to R and the R environment and not to pure java script. I am seeking a solution which I can use in the R environment.
I tried splicing in some java script using the JS() function but that didn't work. Maybe because I do not have an adequate knowledge or understanding of javascript or maybe because the solution should not be sought there - I am not sure. I also dabbled with R's htmltools and htmlwidgets libraries but these libraries are new to me and I am not experienced enough go make that work.
I simply want a label to show when I hover the mouse over the button. That label will tell the user in one word what the button does. Remember that this is not a 'normal' button in shiny but a button added with 'addEasyButton' - it therefore appears on the map created by leaflet (and not separately or next to it).
CodePudding user response:
Never used this package but I just took a look at the doc and easyButton
has a title
argument. This is what you want.
easyButton(id = ...., title = "mylabel", ....)