Przeglądaj źródła

Use updateFrappeChart() to avoid redrawing the whole frappeChart

shiny-input
Garrick Aden-Buie 6 lat temu
rodzic
commit
8d519b645a
2 zmienionych plików z 40 dodań i 1 usunięć
  1. +7
    -1
      inst/shiny-input-app/app.R
  2. +33
    -0
      inst/shiny-input-app/dev-shiny-input.Rmd

+ 7
- 1
inst/shiny-input-app/app.R Wyświetl plik



output$chart_typing_speed <- frappeCharts::renderFrappeChart({ output$chart_typing_speed <- frappeCharts::renderFrappeChart({
frappeCharts::frappeChart( frappeCharts::frappeChart(
data.frame(time = wpm$time, wpm = wpm$wpm),
data.frame(time = 0, wpm = 0),
type = "line", type = "line",
title = "Your Typing Speed", title = "Your Typing Speed",
is_navigable = FALSE, is_navigable = FALSE,
) )
}) })


observeEvent(wpm$time, {
frappeCharts::updateFrappeChart(
inputId = "chart_typing_speed",
data = data.frame(time = wpm$time, wpm = wpm$wpm)
)
})
} }


shinyApp(ui, server) shinyApp(ui, server)

+ 33
- 0
inst/shiny-input-app/dev-shiny-input.Rmd Wyświetl plik



## Use our frappeChart widget to show speed over time ## Use our frappeChart widget to show speed over time


### First pass

`r github_sha_link("fe55bf588400f8586472b1050c0da1b931bad1c3")`

We're going to drop-in our `frappeChart` package to add a dynamic plot We're going to drop-in our `frappeChart` package to add a dynamic plot
showing typing speed over time. showing typing speed over time.


) )
}) })
``` ```

### Don't redraw: Use the update method we made for frappeCharts

Replace the initial `frappeChart()` with a simple placeholder.

```r
# server
output$chart_typing_speed <- frappeCharts::renderFrappeChart({
frappeCharts::frappeChart(
data.frame(time = 0, wpm = 0),
type = "line",
title = "Your Typing Speed",
is_navigable = FALSE,
axisOptions = list(xIsSeries = TRUE),
lineOptions = list(regionFill = TRUE)
)
})
```

and use the `updateFrappeChart()` function to update the chart in place.

```r
observeEvent(wpm$time, {
frappeCharts::updateFrappeChart(
inputId = "chart_typing_speed",
data = data.frame(time = wpm$time, wpm = wpm$wpm)
)
})
```

Ładowanie…
Anuluj
Zapisz