Girafe plot won't display if interrupted before loading

I'm creating a shiny app that utilizes ggiraph to display interactive ggplot charts. The functionality is fantastic, but I'm having an issue where a chart won't display if it's clicked away from while it's still loading and then you go back to that "page" to see the chart.

I created a quick example. When you run the app, click on the tab "Click here!" before the map loads and then click back to the "Map" tab and you will see that the map won't display. If I just use ggplot and don't convert to girafe, the map will display no matter if you click away quick.

Is this normal behavior? Am I doing something wrong? Thanks for any guidance you may have.

library(shiny)
library(sf)
library(ggiraph)
library(tidyverse)
library(shinycssloaders)


# Prepare object ----------------------------------------------------------

sf.object <- system.file("shape/nc.shp", package = "sf")

nc <- st_read(sf.object)

# Define UI for application
ui <- fluidPage(
  tabsetPanel(
    tabPanel("Map",
             girafeOutput("examplemap") %>% withSpinner()),
    
    tabPanel("Click here!")
  )
)

# Define server logic 
server <- function(input, output) {
  
  output$examplemap <- renderGirafe({
    
    plot <- ggplot(nc) +
      geom_sf_interactive(aes(fill = FIPSNO, data_id = FIPS, tooltip = NAME)) +
      scale_fill_gradient()
    
    girafe(code = print(plot))
    
    
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

This topic was automatically closed 21 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.