I have a code that deploys a shiny app with an authentication request, but it doesnt run in shinyapps.io.
Can somebody help me to understand why it doesnt run? Locally it works perfectly
This is my code with the default credentials:
library(shiny)
library(shinymanager)
credentials <- data.frame(
user = c("shiny", "shinymanager"), # mandatory
password = c("azerty", "12345"), # mandatory
start = c("2019-04-15"), # optinal (all others)
expire = c(NA, "2019-12-31"),
admin = c(FALSE, TRUE),
comment = "Simple and secure authentification mechanism
for single ‘Shiny’ applications.",
stringsAsFactors = FALSE
)
ui <- fluidPage(
useShinyjs(),
tags$head(
tags$style(
HTML("
.btn {
background-color: #01DFA5;
color: white; }
body {
background-color: #0B0B3B;
}
.corner-image {
position: absolute;
bottom: 10px;
right: 10px;
width: 180px;
height: 60px;
}
.center-title {
text-align: center;
color: #01DFA5;
}
"
)
)
),
titlePanel(h1("Conciliador MercadoPago", class = "center-title",style = "font-family: Arial, sans-serif;font-style: italic;"), "ConciliadorBI"),
fileInput("file", h6("Seleccione un archivo", style = 'color: #01DFA5;')),
conditionalPanel(
condition = "output.status_message.length > 1",
verbatimTextOutput("status_message")
),
actionButton("process", "Procesar"),
downloadButton("download", "Descargar Resultados en Excel"),
img(src = "https://i.postimg.cc/xdJqdNC1/logo2.png", class = "corner-image")
)
ui <- secure_app(ui)
server <- function(input, output, session) {
res_auth <- secure_server(
check_credentials = check_credentials(credentials)
)
status_message <- reactiveVal("Introduzca un Archivo (.xlxs o .csv)")
processed_data <- reactiveVal(NULL)
observeEvent(input$process, {
req(input$file)
file_ext <- tolower(tools::file_ext(input$file$name))
if (file_ext %in% c("xlsx", "csv")) {
data <- if (file_ext == "xlsx") {
read_excel(input$file$datapath)
} else {
read_csv(input$file$datapath)
}
data$TRANSACTION_AMOUNT <- as.numeric(data$TRANSACTION_AMOUNT)
data <- data[!is.na(data$TRANSACTION_AMOUNT) & data$TRANSACTION_AMOUNT != "-" & data$TRANSACTION_AMOUNT != "/", ]
processed_data(data)
status_message("Archivo procesado. Puede descargar los resultados.")
} else {
status_message("Formato de archivo incorrecto")
}
})
output$download <- downloadHandler(
filename = function() {
"resultados.xlsx"
},
content = function(file) {
data <- processed_data()
if (!is.null(data)) {
wb <- createWorkbook()
sheet <- addWorksheet(wb, "Resultados")
if (nrow(data) == 0) {
writeDataTable(wb,sheet, data.frame(SOURCE_ID = character(0), USER_ID = character(0), TRANSACTION_AMOUNT = numeric(0)),
colNames = TRUE, rowNames = FALSE)
} else {
subset_data <- data[, c("SOURCE_ID", "USER_ID", "TRANSACTION_AMOUNT")]
writeDataTable(wb, sheet, subset_data, colNames = TRUE, rowNames = FALSE)
}
saveWorkbook(wb, file)
}
}
)
output$status_message <- renderText({
status_message()
})
output$auth_output <- renderPrint({
reactiveValuesToList(res_auth)
})
}
shinyApp(ui, server)