It seems, that the problem is caused by the specific encoding, which shinyapps.io doesn't recognize.
The function fileInput()
tries to read the file content immediately in order to wrap it to data.frame
with the predefined structure, and it fails when unknown encoding or corrupted file is provided. From the other hand, shinyapps.io has restricted possibilities to setup environment and encoding.
So, instead I'd suggest an alternative way of reading files with readLines()
function. In the below example the user has to provide URL, which is then being read into a reactive variable. The variable then can be analyzed or processed. The test URL from your example does not cause errors.
library(shiny)
ui <- shiny::fluidPage(
fileInput("file", "Upload file"), # FileInput (1)
textOutput("content1"), # Text fragment (1)
textInput("url", label = "Provide URL"), # URL input (2)
actionButton("download", label = "Read file"),
textOutput("content2") # Text fragment (2)
)
server <- function(input, output) {
reactive_val <- reactiveValues()
# File content
output$content1 <- renderText({
if (is.null(input$file)) return(NULL)
x <- readLines(input$file$datapath, n = 5, skipNul =T)
enc2native(x)
})
# Read URL content
observeEvent(input$download, {
my_file <- input$url
if (is.null(my_file)) return(NULL)
file_content <- readLines(my_file, n = 5, skipNul =T)
reactive_val[["content"]] <- enc2native(file_content)
}, ignoreInit = T)
# URL file content
output$content2 <- renderText({
if (is.null(reactive_val[["content"]])) return(NULL)
reactive_val[["content"]]
})
}
shinyApp(ui, server)