Fixing the Shiny App Warning: A Solution for tmap_leaflet Users

Problem Publishing Shiny App - Warning in renderWidget(instance) : Ignoring appended content; appendContent can’t be used in a Shiny render call

Introduction

This article aims to help users who encounter an error while publishing their Shiny app online. The issue arises when the renderLeaflet function, which is used to display leaflet maps within the app, triggers a warning message that causes the app to fail deployment on shinyapps.io.

The problem is not directly related to the code itself but rather with how Shiny handles certain features, particularly in the context of tmap_leaflet. In this article, we’ll delve into the details of this issue and explore potential solutions.

Understanding the Warning Message

When attempting to publish a Shiny app that includes a leaflet map generated using the renderLeaflet function, users may encounter the following warning message:

Warning in renderWidget(instance) :
  Ignoring appended content; appendContent can't be used in a Shiny render call

This warning is caused by an internal conflict within the Shiny rendering mechanism. Specifically, it arises when appendContent is applied to the output of a server function that does not support this functionality.

Background Information on tmap_leaflet

The tmap_leaflet function from the tmap package generates leaflet maps using R’s ggplot2 package as input. This integration enables users to create interactive, web-based maps with R. However, when used within Shiny, it presents some challenges due to its nature.

Why does in.shiny = TRUE Solve the Issue?

In order for renderLeaflet to function correctly and avoid warnings like the one encountered above, we need to set in.shiny = TRUE. This setting disables certain features that are not supported within Shiny applications. By doing so, it allows us to get around the internal conflicts that prevent our leaflet map from rendering properly.

Example Solution

To fix this issue and ensure your app deploys successfully on shinyapps.io, you can modify the code as follows:

output$turbinemap <- renderLeaflet({
    mymap <-tm_shape(windturbine_sf) + 
        tm_dots(col="indianred1",popup.vars=c("Project Name"="project_name","Total project capacity(MW)"="total_project_capacity_mw"))
    tmap_leaflet(mymap, in.shiny = TRUE)
})

By adding the in.shiny = TRUE argument to the renderLeaflet function call, we’re effectively disabling the unsupported features that were causing the warning message. This solution should resolve any issues related to Shiny app deployment and ensure a smooth user experience.

Conclusion

In this article, we explored an error encountered while publishing Shiny apps on shinyapps.io due to a conflict with tmap_leaflet functions. By understanding the root cause of the issue and applying the suggested fix by setting in.shiny = TRUE, users can successfully deploy their Shiny apps without any complications.

If you’re experiencing similar issues or need further assistance, feel free to reach out.


Last modified on 2025-04-15