Hello,
I'm using fileInput() to read and then parse an xml file (with the xml2 package), and then output the selected data. My code works in a normal R script, but when I run it in shiny, after I upload the file, I get the error: no applicable method for 'read_xml' applied to an object of class "NULL".
Below is a simplified example of my app structure:
library(shiny)
library(xml2)
# make a file to upload
h <- read_html("<p>Hi!</p>")
write_xml(h, "mydata.xml", options = "format", encoding = "UTF-8")
ui <- fluidPage(
fileInput("File", "Choose file"),
tableOutput("Data")
)
server <- function(input, output, session) {
Data <- eventReactive(input$File, {
read_xml(input$File$datapath)
})
output$Data <- renderTable({
head(xml_text(Data()))
})
}
shinyApp(ui, server)