html not rendering in leaflet shinyapp

I am working on a shinyapp using the leaflet maps. I have been trying to add some popup information, however instead of rendering the HTML as bold, hyperlinks, etc, it just displays the raw text when I click on each point.

The markers are declared in a leafletProxy:

  observe({
    user_selected_cats = get_selected_categories()
    selected_samples = dplyr::filter(metagenomedata, category %in% user_selected_cats )

    leafletProxy("worldMap", data=selected_samples) %>%
      clearMarkers() %>%
      addCircleMarkers(lng=selected_samples$longitude , lat=selected_samples$latitude ,
                       stroke=FALSE, fillOpacity=0.25,
                       fillColor= selected_samples$colorvec ,
                       popup = ~htmlEscape(selected_samples$sra_labels)
                       )
  }) # end observe

They end up looking like this:

Am I missing something obvious? Thanks in advance!

Can't be fully certain without having access to your data; but it seems that you are applying htmlEscape function to your labels - in effect making them forget their HTML behaviour, and forcing them to render as text.

Try removing the function, it should help.

Yep, that seems to do it! Thanks!
What exactly does htmlEscape() do, or when should this be used? The leaflet guides were showing this for nearly all the cases.

Glad to be of service!

htmlEscape function does what it says - it sanitizes its input so that it is not rendered as HTML (including any potentially malicious javascript) but as a safe text.

Using it is a best practice in situations where you do not have control over the HTML being rendered (say if it comes from a user input). On the other hand when you do have full control over the HTML input it is not the best idea, as you might want to actually render the HTML - including stuff like links, images and bold / italics font. So context matters.

Exploits of a Mom

Note that I am contractually obliged to illustrate the point with this oldish XKCD strip.
I am sorry, but I don't make the rules :slight_smile:

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.