Shiny App with leaflet map runs well in Rstudio but when I try to deploy it in shinyapps.io, it deploys but then I just get an error message

31 Views Asked by At

Below is some sample code for a shiny app I am trying to deploy on shinyapps.io. Whilst it runs just fine in Rstudio, when I deploy it it deploys but then just shows an error message on the browser page. Please help!

Is it perhaps something with leaflet, sf or rnaturalearth. Really scratching my head here. Thanks

# Load required libraries
library(shiny)
library(leaflet)
library(rnaturalearth)
library(sf)

# Download and load Natural Earth data for Australian states
aus_states <- ne_states(country = "Australia", returnclass = "sf")

# Generate random data for Australian states
set.seed(123) # For reproducibility
aus_states$Value <- runif(nrow(aus_states), min = 1, max = 100)

# Define UI
ui <- fluidPage(
  titlePanel("Australian State Choropleth Map with Random Data"),
  mainPanel(
    leafletOutput("map")
  )    
)

# Define server logic
server <- function(input, output) {
  # Render the choropleth map
  output$map <- renderLeaflet({
    leaflet(data = aus_states) %>%
      addProviderTiles("CartoDB.Positron") %>%
      addPolygons(
        fillColor = ~colorQuantile("YlOrRd", Value)(Value),
        fillOpacity = 0.7,
        color = "#BDBDC3",
        weight = 1,
        highlight = highlightOptions(
          weight = 3,
          color = "#666",
          fillOpacity = 0.7,
          bringToFront = TRUE
        ),
        label = ~paste(name, ": ", round(Value, 2)),
        labelOptions = labelOptions(
          style = list("font-weight" = "normal", padding = "3px 8px"),
          textsize = "15px",
          direction = "auto"
        )
      ) %>%
      addLegend(
        "bottomright",
        pal = colorQuantile("YlOrRd", aus_states$Value),
        values = ~Value,
        title = "Value",
        labFormat = labelFormat(digits = 1)
      ) %>%
      setView(lng = 133, lat = -27, zoom = 4)  # Set initial map view
  })
}

# Run the app
shinyApp(ui = ui, server = server)
0

There are 0 best solutions below