Home > database >  can you manipulate an uploaded file in flexdashboard
can you manipulate an uploaded file in flexdashboard

Time:05-27

Following on from Uploading a File in a flexdashboard, is it possible to assign the read file to a variable and perform actions on it

Currently, I would do this to view the uploaded file:

dataset1 <- eventReactive(input$file1,{
  dataset <- read.csv(input$file1$datapath)
})

fileInput("file1", "Upload Data Sheet",
                    multiple = TRUE,
                    accept = c("text/csv",
                             "text/comma-separated-values,text/plain",
                             ".csv"))

renderTable({
  dataset1()
  
})

I tried to assign it to an object that can be manipulated like a dataframe with:

z = renderTable({
  dataset1()
  
})

dim(z) # or z %>% filter(...) or z %>% mutate(new = 5) ...

But end up with error saying no applicable method for 'mutate' applied to an object of class "c('shiny.render.function', 'function')"

This makes me think that I cannot manipulate an uploaded file.

Is this the case, or is there a workaround?

CodePudding user response:

But z is not the dataset itself, is just a shiny output created from it.

You can manipulate the data inside the reactive function, e.g.:

z <- renderTable({
  dataset1() %>%
    dim()
})
  • Related