Manipulating a user-uploaded file/data in R shiny

Viewed 412

I've been working on an R shiny app that is supposed to take a user-uploaded .csv file, do a bunch of manipulations/calculations to that data, and then spit out some graphs. I am completely new to shiny, however, and am very lost. I've tried to look this up, but most results I found take the data and directly show it in a graph. So far I've tried this (code is taken from here):

UI:

ui <- fluidPage(
  fileInput("userfile", "Choose CSV File", multiple = TRUE,
     accept=c("text/csv","text/comma-separated-values,text/plain",".csv")),
  # etc.

Server:

server <- function(input,output){
  df <- read.csv(input$userfile$datapath)
  # some manipulation, such as adding a new column, for example:
  df$timestwo <- 2 * df$column1
}

Is df in the Server code supposed to be the dataframe that was read in from the user-uploaded file? If not, how can I create a dataframe that is able to go through several changes, before making a graph? When I try to run my code I get "Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer." Thanks!

Edit to add: all the data manipulation I wanted to do worked with my sample dataset, but not the user-input one I tried out (which was the exact same data).

0 Answers
Related