My goal is to make a reactive shiny function in R. There are multiple outputs (e.g. tables) which can be bind to a similar function. However I need the function to react on some parameter, specific to one table. Here is some simple sample code, which isn't working but it makes my idea clear - I hope:
output$tableOne <- DT::renderDataTable({
getData(foo)
})
getData <- reactive(function(funParameter){
corrStartDate <- input$StartDate
corrEndDate <- input$EndDate
return(someData(corrStartDate, corrEndDate, funParameter))
})
In all tables (if there is more then one) I wan't to show data with different base parameter (getData(x, y, foo)). So the second table could use "getData(x, y, bar)". I don't want to write every time the same function for another table.
The solution above is not working, since reactive functions do not support parameters.
How would you solve this?
This should work instead:
getData <- eventReactive(input$funParameter, {
corrStartDate <- input$StartDate
corrEndDate <- input$EndDate
return(someData(corrStartDate, corrEndDate, input$funParameter))
})
eventReactive
only updates if arguments stated up front change. Practically speaking, this reactive will not trigger if input$StartDate
or input$EndDate
changes.
If this is not what you want, normal reactive functions should work. I.e.:
getData <- reactive({
funParameter <- input$funParameter
corrStartDate <- input$StartDate
corrEndDate <- input$EndDate
return(someData(corrStartDate, corrEndDate, funParameter))
})
which will trigger if any of the inputs change
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With