Skip to content

Commit

Permalink
+ README
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Jan 27, 2024
1 parent 2d06b9d commit f190ba9
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 4 deletions.
52 changes: 50 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ knitr::opts_chunk$set(

The goal of `react` is to help with reactivity, instead of calling the `foo`
reactive expression `foo()` you can call `react$foo` similar to how one
calls `input$bar` for inputs.
calls `input$bar` for inputs, or alternatively `react[foo]` or `react[foo()]`.

The benefit is that it makes it easier to identify calls to reactive expressions
The benefit is that it makes it easier to spot calls to reactive expressions
in your server code.

## Installation
Expand All @@ -33,3 +33,51 @@ You can install the development version of react from [GitHub](https://github.co
``` r
pak::pak("tadascience/react")
```

## Examples

Take this from the shiny example:

```r
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(dataInput(), theme = chartTheme("white"),
type = "line", log.scale = input$log, TA = NULL)
})

}
```

With `react` you can rewrite the `plot` output as one of these, depending on your
taste.

```r
# react$ is similar conceptually to how input$ works
output$plot <- renderPlot({
chartSeries(react$dataInput, theme = chartTheme("white"),
type = "line", log.scale = input$log, TA = NULL)
})

# react[]
output$plot <- renderPlot({
chartSeries(react[dataInput], theme = chartTheme("white"),
type = "line", log.scale = input$log, TA = NULL)
})

# react[()] so that you still have the calling a function feel
# and you just sourround it
output$plot <- renderPlot({
chartSeries(react[dataInput()], theme = chartTheme("white"),
type = "line", log.scale = input$log, TA = NULL)
})

```

52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

The goal of `react` is to help with reactivity, instead of calling the
`foo` reactive expression `foo()` you can call `react$foo` similar to
how one calls `input$bar` for inputs.
how one calls `input$bar` for inputs, or alternatively `react[foo]` or
`react[foo()]`.

The benefit is that it makes it easier to identify calls to reactive
The benefit is that it makes it easier to spot calls to reactive
expressions in your server code.

## Installation
Expand All @@ -23,3 +24,50 @@ You can install the development version of react from
``` r
pak::pak("tadascience/react")
```

## Examples

Take this from the shiny example:

``` r
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(dataInput(), theme = chartTheme("white"),
type = "line", log.scale = input$log, TA = NULL)
})

}
```

With `react` you can rewrite the `plot` output as one of these,
depending on your taste.

``` r
# react$ is similar conceptually to how input$ works
output$plot <- renderPlot({
chartSeries(react$dataInput, theme = chartTheme("white"),
type = "line", log.scale = input$log, TA = NULL)
})

# react[]
output$plot <- renderPlot({
chartSeries(react[dataInput], theme = chartTheme("white"),
type = "line", log.scale = input$log, TA = NULL)
})

# react[()] so that you still have the calling a function feel
# and you just sourround it
output$plot <- renderPlot({
chartSeries(react[dataInput()], theme = chartTheme("white"),
type = "line", log.scale = input$log, TA = NULL)
})

```

0 comments on commit f190ba9

Please sign in to comment.