🏥 🏭 Working on the COVID-19 response in Canada? Plotly & the Canadian government can help you and your organization. Learn more and get in touch.

Plotly 3D globe not rendering in Shiny app

I have been trying to get a 3D globe to appear in the Shiny app. The code works perfectly outside of the renderLeaflet (i.e. the globe appears), but not inside it (i.e. the globe does not show up).

Any advise on how to rectify the situation would be most appreciated:

ui <- fluidPage(
  mainPanel( 
    leafletOutput("map"), 
  ))


server <- function(input, output) {

  output$map <- renderLeaflet({

    pal <- c("black", "blue", "red")

    axis_props <- list(
      showgrid = T, gridcolor = toRGB("gray40"), gridwidth = 0.5
    )
    globe <- list(
      showland = T, showlakes = T, showcountries = T, showocean = T,
      countrywidth = 0.5,
      landcolor = toRGB("grey90"),
      lakecolor = toRGB("white"),
      oceancolor = toRGB("white"),
      projection = list(
        type = 'orthographic',
        rotation = list(
          lon = -100, lat = 40, roll = 0
        ),
        lonaxis = axis_props,
        lataxis = axis_props
      )
 )

    # Loading plotly
    plot_geo(width = 600, height = 600, locationmode = 'country names') %>%  # initializing plotly object
      add_trace(type = 'scatter', locations = ~countries, showscale = T, z = ~HIndex,
                color = ~HIndex, colors = pal, hoverinfo = 'text', text = ~paste(countries, HIndex)) %>%
      colorbar(title = 'Happiness Index', title = 'Happiness Index of Countries') %>%
      layout(geo = globe, title = "Happiness Index of Countries Around the World (2019)")


 })


}


shinyApp(ui = ui, server = server)