Not able to fetch value of variable outside function

111 views Asked by At

I'm trying get value of variable "corpus" outside reactive function. I'm creating Shiny app where it is mandatory to define readcsv <- read.csv(inFile$datapath) inside reactive function. Can anybody please help how I can get the dataframe value of corpus outside reactive function data1().

server.R

data1 <- reactive({
inFile <- input$file1
if (is.null(inFile)){
return(NULL)
}
#Read csv file
readcsv <- read.csv(inFile$datapath)

#Create Corpus
corpus <- Corpus(VectorSource(readcsv$Tweets))

})

ui.R

fileInput("file1", "Choose CSV File",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv")
)
1

There are 1 answers

0
mabdrabo On

The following will put the output of Corpus(...) in data1

data1 <- reactive({
    inFile <- input$file1
    if (is.null(inFile)){
        return(NULL)
    }
    #Read csv file
    readcsv <- read.csv(inFile$datapath)

    #Create Corpus
    Corpus(VectorSource(readcsv$Tweets))
})

Then you can use it anywhere in server like so

corpus <- data1()