hello I am building a r shiny app and it works well when I use it locally but doesnot work when I deploy it.
i am new here.
here is my code:
library(shiny)
library(readr)
library(leaflet)
library(tmaptools)
library(dplyr)
library(tidygeocoder)
library(sf)
library(DT)
Load the CSV file from a URL
data <- read_csv("https://drive.google.com/uc?export=download&id=1dbw7P47-Wv0EqVPawIJFmnTtwXkUYKDs")
vendors<- read_csv("https://drive.google.com/uc?export=download&id=1s70gtfLOajwbDxnv8AvowKXWyQ5prL0i")
ui <- fluidPage(
titlePanel("School Details and Map"),
sidebarLayout(
sidebarPanel(
selectInput("city", "Select City", choices = unique(data$City)),
selectInput(inputId = "school_name", label = "Select a School Name:", choices = NULL)
),
mainPanel(
fluidRow(
column(width = 12,
verbatimTextOutput("invalid_address")
)
),
fluidRow(
column(width = 12,
leafletOutput(outputId = "map")
)
),
fluidRow(
column(width = 12,
dataTableOutput("vendor_table")
)
)
)
)
)
server <- function(input, output, session) {
a4=observe({
schools_in_selected_city <- data[data$City == input$city, ]
updateSelectInput(session, "school_name", choices = schools_in_selected_city$School Name
)
})
hg=reactiveVal()
output$map <- renderLeaflet({
selected_address <- data[data$School Name
== input$school_name, ]
address <- selected_address
vendor<-vendors[vendors$City == input$city, ]
location <- address%>%
geocode(`Complete Address`)
l1 <- location %>%
filter(!is.na(lat))
location1<-vendor%>%
geocode(`Full Address`)
l <- location1 %>%
filter(!is.na(lat))
if (!is.null(location)) {
a=st_as_sf(l1, coords=c("long","lat"),crs=4326)
b=st_buffer(a,dist = 8000)
c=st_as_sf(l, coords=c("long","lat"),crs=st_crs(b))
vendors_inside=st_intersection(c,b)
hg(vendors_inside)
map <- leaflet() %>%
addTiles() %>%
addMarkers(data=a, popup = input$school_name) %>%
addCircles(data=a, radius = 8000) %>%
addCircles(data=vendors_inside,popup=vendors_inside$Store.Name)
return(map)
}
})
output$vendor_table <- renderDataTable({
# Access the sf dataset from the reactiveValues object
gh=hg()
selected_cols <- c("Store.Name", "Full.Address","School.Name",'Complete.Address',"City","Contact.details","Principal.Name") # Replace with your column names
datatable(gh[, selected_cols], options = list(pageLength = 30))
# Display the first few rows of the spatial data as a table
})
}
shinyApp(ui = ui, server = server)
so do chose the city as brampton you will find the thing I want to achieve at first it might show error due to geocoding problem but it you choose brampton the geocoding works fine.