0

This is my server.R.

  • I created data() using reactive
  • I called data() using a function I created StructureAutomation. However, data() is not passed into StructureAutomation.
  • NOTE: StructureAutomation function is defined in functions.R. It expects a dataset as the first input parameter.

server.R

source("./functions.R")

options(shiny.maxRequestSize=40*1024^2)


function(input, output) {

  data <- reactive({

    xdata <- input$inFile
    if (is.null(xdata))
      return(NULL)
    ydata = read.csv(xdata$datapath,header=input$header,sep=",")
    data = ydata[order(ydata[,1],ydata[,2]),]
    data


})


  output$structure <- renderTable({

    data=data()

    StructureAutomation(data,nlevels=input$level,buildout=FALSE)
    as.data.frame(count(node))

  })

}
HubertL
  • 19,246
  • 3
  • 32
  • 51
Ketty
  • 811
  • 10
  • 21
  • Can you provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? – Samuel May 16 '17 at 20:37
  • What do you mean by "not passed"? Did it return a null? BTW I wouldn't keep reusing the variable name `data`. That is bound to lead to confusing name collisions and errors. – Mike Wise May 17 '17 at 08:26

2 Answers2

0

to pass the data to the function you have to return the data in your reactive event.

source("./functions.R")

options(shiny.maxRequestSize=40*1024^2)


function(input, output) {

  data <- reactive({

    xdata <- input$inFile
    if (is.null(xdata))
      return(NULL)
    ydata = read.csv(xdata$datapath,header=input$header,sep=",")
    data = ydata[order(ydata[,1],ydata[,2]),]
    return(data)
})

  output$structure <- renderTable({

    data=data()

    StructureAutomation(data,nlevels=input$level,buildout=FALSE)
    as.data.frame(count(node))

  })

}

And as Mike Wise already mentioned, I wouldn't name the function, the output and following variables the same.

jkrainer
  • 413
  • 5
  • 10
0

Thank you, all! It was a stupid mistake.

I should have declared data as a global variable.

Appreciate all your help!

runStructure <- eventReactive (input$runButton, {
    xdata = input$inFile
    if (is.null(xdata))
      return(NULL)
    ydata = read.csv(xdata$datapath,header=input$header,sep=",")
    data <<- ydata[order(ydata[,1],ydata[,2]),]   

    StructureAutomation(data,nlevels=input$level,buildout=FALSE)
    as.data.frame(count(node))
})
Ketty
  • 811
  • 10
  • 21