incRv: In-line numeric operation for reactiveVal

Description Usage Arguments Details Value See Also Examples

View source: R/spsServerCollections.R

Description

In-place operations like i += 1, i -= 1 is not support in R. These functions implement these operations in R. This set of functions will apply this kind of operations on [shiny::reactiveVal] objects.

Usage

1
2
3
4
5
incRv(react, value = 1)

multRv(react, value = 2)

diviRv(react, value = 2)

Arguments

react

reactiveVal object, when it is called, should return an numeric object

value

the numeric value to do the operation on react

Details

incRv(i) is the same as i <- i + 1. incRv(i, -1) is the same as i <- i - 1. multRv(i) is the same as i <- i * 2. diviRv(i) is the same as i <- i / 2.

Value

No return, will directly change the reactiveVal object provided to the react argument

See Also

If you want shiny::reactiveValues version of these operators or just normal numeric objects, use spsUtil::inc, spsUtil::mult, and spsUtil::divi.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
reactiveConsole(TRUE)
rv <- reactiveVal(0)
incRv(rv) # add 1
rv()
incRv(rv) # add 1
rv()
incRv(rv, -1) # minus 1
rv()
incRv(rv, -1) # minus 1
rv()
rv2 <- reactiveVal(1)
multRv(rv2) # times 2
rv2()
multRv(rv2) # times 2
rv2()
diviRv(rv2) # divide 2
rv2()
diviRv(rv2) # divide 2
rv2()
reactiveConsole(FALSE)
# Real shiny example
if(interactive()){
  ui <- fluidPage(
    textOutput("text"),
    actionButton("b", "increase by 1")
  )
  server <- function(input, output, session) {
    rv <- reactiveVal(0)
    observeEvent(input$b, {
      incRv(rv)
    })
    output$text <- renderText({
      rv()
    })
  }
  shinyApp(ui, server)
}

spsComps documentation built on Feb. 3, 2022, 1:07 a.m.