简体   繁体   中英

R Shiny - Using eventReactive output inside Reactive

I am trying to rebase something if the rebase button is clicked (input$rebase). If it is not clicked, then I want the code to continue with value_new just being value. But if it is clicked, then i want to use the output from rebasesomething ie, i want value_new to be value * 0.5.

How can i do this? I tried the ifexists to see if that function has an output or not (ie if the button has been clicked and some output generated), but that doesn't seem to work. Any other ideas on how this could be done?

Sorry to not give a working example, but the code is huge, just hoping someone can guide me in the right direction.

reactive({
     value <- input$value

     value_new<-value

     ifexists(rebasesomething()){value_new<-value*rebasesomething()}
 
#do a whole bunch of other things with value_new
})


rebasesomething <- eventReactive(input$rebase,{
      
      temp<-0.5
      temp
    })

Found the solution, can just use if(input$rebase) to say if a button has been clicked or not:

if (input$rebase){
      
      value_new<-value*rebaselist()
      
    }
    else {
      value_new<-value
      
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM