Hi I'd be so grateful for any insights into this issue.
I have created my first useful Shiny app - it works locally, and I can publish the built-in Geyser app. But if I publish my own app, I get: "An error has occurred, The application failed to start. exit status 1" (after a decent wait).
Any idea what might be happening? Here's the R code:
library(shiny)
library(DBI)
library(RMySQL)
library(DT)
library(writexl)
setwd("H:/My Drive/Dashboard/Shiny/SpecificSearch/VID_Result_List")
# Define UI for the app
ui <- fluidPage(
# App title
titlePanel("VID Search"),
# Main panel for displaying outputs
mainPanel(
# Output: DataTable
DTOutput("vidTable"),
# Download controls
radioButtons(inputId = "filetype",
label = "File type:",
choices = c("CSV" = "csv", "Excel" = "xlsx"),
selected = "csv"),
downloadButton(outputId = "downloadData", label = "Download Data")
)
)
# Define server logic
server <- function(input, output, session) {
# Database connection details
con <- dbConnect(RMySQL::MySQL(),
dbname = "****",
host = "****",
port = 3306,
user = "*****",
password = "*****")
# Initial data query
query <- "SELECT idIncident,
dateincident AS `Incident Date`,
title AS Title,
countryname AS Country,
statename AS `State/Province`,
cityname AS City,
otherDireccion AS `Other Address`,
driverperse AS `Responsible Actor Category`,
victimreligion AS `Religion of Victim(s)`
FROM tbl_incident2
WHERE idStatus = 0 AND securitylevel = 'Public'
ORDER BY idIncident DESC;"
VID <- dbGetQuery(con, query)
# Close the database connection when the app stops
onStop(function() {
dbDisconnect(con)
})
# Render DataTable
output$vidTable <- renderDT({
datatable(VID,
options = list(pageLength = 10),
rownames = FALSE,
extensions = 'Buttons',
selection = 'none',
class = 'cell-border stripe',
style = 'bootstrap',
width = "100%"
)
})
# Download handler
output$downloadData <- downloadHandler(
filename = function() {
paste("VID_report-", Sys.Date(), ".", input$filetype, sep = "")
},
content = function(file) {
if (input$filetype == "csv") {
write.csv(VID, file, row.names = FALSE)
} else {
write_xlsx(VID, file)
}
}
)
}
# Run the application
shinyApp(ui = ui, server = server)