Neil
Neil

Reputation: 8247

how to call variable defined in reactive function of shiny in other reactive function

I have following server.r file in Shiny

 enterdata <- reactive({
     a <- "Hello"
     b <- data.frame()

 })

How would I call variable a in other reactive function. I have dataframe as weell in enterdata,but I want only a to be called in other function

 getdata <- reactive({

    sum <- paste(enterdata()$a,"Neil")

 })   

Is the above right way to do it?

Upvotes: 0

Views: 1216

Answers (1)

Marta
Marta

Reputation: 3152

You should treat reactive as a function. Therefore if you want to return more then one value put it for example in a list, like here:

enterdata <- reactive({
    a <- "Hello"
    b <- data.frame()

    list(a = a, b = b)

 })

Later you can just treat it as list:

getdata <- reactive({
    sum <- paste(enterdata()$a,"Neil")
 })  

Upvotes: 2

Related Questions