I have a code in shiny, which reads a dataframe like below. It works normally locally, I deployed the app using shinyapps.io (https://testeeeeeeee.shinyapps.io/Rota_alimentos/), but it doesn't read my dataframe that is in the code when I use the mentioned website, what am I doing wrong?
Code:
library(shiny)
library(shinythemes)
library(lubridate)
library(googleway)
library(shinyjs)
library(shinyWidgets)
library(shinyBS)
df1<- structure(
list(
Marketname = c("Manzini", "Manzini","Jaú","Jaú", "Central", "Central", "Confiança","Confiança"),
Days = c("segunda-feira","segunda-feira","segunda-feira","terça-feira", "segunda-feira","terça-feira","segunda-feira","segunda-feira"),
Openinghours = c("Manhã","Tarde", "Manhã","Tarde","Tarde","Tarde","Manhã","Tarde"),
Latitude = c(-22.91668421655409,-22.91668421655409, -22.89279876292728,-22.89279876292728,-22.89107669207457,-22.89107669207457,-22.900200453490385, -22.900200453490385),
Longitude = c(-48.43786997555729,-48.43786997555729,-48.45043377250408,-48.45043377250408,-48.44108027972275,-48.44108027972275,-48.448779371935494,-48.448779371935494)),
row.names = c(NA, 8L), class = "data.frame")
ui <- fluidPage(
useShinyjs(),
shiny::navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
br(),
tabPanel("Rota",
sidebarLayout(
sidebarPanel(
uiOutput ("date"),
selectizeInput("hours",
label = h5("Escolha um turno:"), choices = NULL,
multiple = TRUE,
options = list(maxItems = 1)),
selectizeInput("market1", label = h5("Escolha o ponto de partida:"), choices = NULL,
multiple = TRUE,
options = list(maxItems = 1)),
selectizeInput("market2", label = h5("Escolha o ponto de destino:"), choices = NULL,
multiple = TRUE,
options = list(maxItems = 1)),
disabled(textInput(inputId = "routeOrder", label = "Ordem das rotas:")),
actionButton(inputId = "getRoute", label = "Gerar rota")),
mainPanel(
tabsetPanel(
tabPanel("Rota",google_mapOutput(outputId = "mapWarsaw",width = "95%", height = "600"),
)
))
))))
server <- function(input, output,session) {
week_day <- reactive({
wday(input$date, label = TRUE, abbr = FALSE)
})
output$date <- renderUI({
tagList(dateInput("date", "Escolha um dia:",format = "dd-mm-yyyy"),
tags$script(HTML('
setTimeout(function(){
$("#date input")[0].value = "Nenhuma data selecionada";
}, 50);
'))
)
})
observe({
updateSelectizeInput(session, "hours",
choices = unique(df1[df1$Days == week_day(), "Openinghours"]),
)
})
observe({
updateSelectizeInput(session, "market1",
choices = unique(df1[df1$Days == week_day() & df1$Openinghours %in% input$hours, "Marketname"])
)
})
observe({
updateSelectizeInput(session, "market2",
choices = unique(df1[df1$Days == week_day() & df1$Openinghours %in% input$hours & df1$Marketname != input$market1, "Marketname"])
)
})
observeEvent(input$getRoute, {
origin <- df1[df1$Marketname == input$market1, c("Latitude", "Longitude")][1, ]
print(origin)
destination <- df1[df1$Marketname == input$market2, c("Latitude", "Longitude")][1, ]
print(destination)
waypoints_df <- df1[df1$Days == week_day() &
df1$Openinghours %in% input$hours &
df1$Marketname != input$market1 &
df1$Marketname != input$market2, c("Latitude", "Longitude", "Marketname")]
waypoints <- lapply(1:nrow( waypoints_df[1:2]), function(i) {
as.numeric( waypoints_df[1:2][i, ])})
if (all(is.na(unlist(waypoints))) || length(waypoints) == 0) {
route <- google_directions(origin = origin,
destination = destination,
mode = "driving")
} else {
route <- google_directions(origin = origin,
destination = destination,
waypoints = waypoints,
optimise_waypoints = TRUE,
mode = "driving")
}
df_routes <- data.frame(polyline = direction_polyline(route))
df_way <- cbind(
route$routes$legs[[1]]$start_location,
data.frame(Marketname = route$routes$legs[[1]]$start_address, address = route$routes$legs[[1]]$start_address))
df_way <- unique(df_way)
df_way$order <- as.character(1:nrow(df_way))
m3<-google_map() %>%
add_polylines(data = df_routes, polyline = "polyline", stroke_weight = 4)%>%
add_markers(data = df_way,
label = "order")
m3<- m3 %>% add_markers(data = destination,
lat = destination[1],
lon = destination[2],
label = as.character(nrow(df_way)+1)) %>%
clear_traffic() %>%
clear_polylines() %>%
clear_markers() %>%
add_traffic()
output$mapWarsaw <- renderGoogle_map({
m3
})
updateTextInput(session, "routeOrder", value = paste0(input$market1, " -> ",
paste(df1[df1$Days == week_day() & df1$Openinghours %in% input$hours &
df1$Marketname != input$market1 &
df1$Marketname != input$market2, "Marketname"], collapse = " -> "), " -> ", input$market2))
})
}
shinyApp(ui = ui, server = server)