Dimitri Petrenko Dimitri Petrenko - 10 months ago 70
R Question

Cant read an .RData fileInput with shiny

I want to import a .RData file with fileInput but It doesnt work, I have this error message :

Error in my.data$TYPE_DE_TERMINAL : $ operator is invalid for
atomic vectors

dt <- reactive({

inFile <- input$file1

if (is.null(inFile))


GetData <- reactive({
my.data <- dt()

When I try my application with a .RData imported manually it works well (I remplaced dt() directly with a dataframe in my directory) ...

Thank you in advance !

Answer Source

The following example solved my problem. It allows you to upload all .RData files. The approach with load and get allows you to assign the loaded data to a variable name of your choice. For the matter of the example being "standalone" I inserted the top section that stores two vectors to your disk in order to load and plot them later.


# Define two datasets and store them to disk
x <- rnorm(100)
save(x, file = "x.RData")
y <- rnorm(100, mean = 2)
save(y, file = "y.RData")

# Define UI
ui <- shinyUI(fluidPage(
  titlePanel(".RData File Upload Test"),
    fileInput("file", label = ""),

# Define server logic
server <- shinyServer(function(input, output) {
    if ( is.null(input$file)) return(NULL)
    inFile <- isolate({input$file })
    file <- inFile$datapath
    # load the file and get it's name
    data <- load(file)
    # assign the loaded data to the variable data
    data <- get(data)
    output$hist <- renderPlot({

# Run the application 
shinyApp(ui = ui, server = server)