The react
object gives alternative syntax to call
shiny reactive expressions.
Examples
# This works by invoking the function from the parent environment
# with no arguments ...
foo <- function() {
42
}
react$foo
#> [1] 42
react[foo]
#> Error in get(as.character(expr, frame)): object 'foo' not found
react[foo()]
#> Error in get(as.character(expr[[1L]], frame)): object 'foo' not found
# You can also use `react()` as a function to wrap the
# reactive call
react(foo())
#> [1] 42
# The benefit is that `react()` can also wrap `input$` calls
# so that you easily recognize reactivity
if (FALSE) {
# ... but it only becomes relevant when used in shiny
# server code, e.g. this app from the shiny page
# with react$dataInput instead of dataInput()
server <- function(input, output) {
dataInput <- reactive({
getSymbols(input$symb, src = "yahoo",
from = input$dates[1],
to = input$dates[2],
auto.assign = FALSE)
})
output$plot <- renderPlot({
chartSeries(react$dataInput, theme = chartTheme("white"),
type = "line", log.scale = input$log, TA = NULL)
})
}
}