Kaynağa Gözat

Complete R function

master
Garrick Aden-Buie 6 yıl önce
ebeveyn
işleme
cbc25a8f7b
3 değiştirilmiş dosya ile 66 ekleme ve 2 silme
  1. +16
    -2
      R/frappeChart.R
  2. +28
    -0
      dev/dev.Rmd
  3. +22
    -0
      dev/widget_demo.Rmd

+ 16
- 2
R/frappeChart.R Dosyayı Görüntüle

@@ -5,11 +5,25 @@
#' @import htmlwidgets
#'
#' @export
frappeChart <- function(message, width = NULL, height = NULL, elementId = NULL) {
frappeChart <- function(
data,
type = c("line", "bar", "pie", "percentage", "heatmap"),
title = "",
...,
is_navigable = TRUE,
width = NULL,
height = 250,
elementId = NULL
) {

# forward options using x
x = list(
message = message
title = title,
type = match.arg(type),
height = height,
data = data,
isNavigable = is_navigable,
...
)

# create widget

+ 28
- 0
dev/dev.Rmd Dosyayı Görüntüle

@@ -393,3 +393,31 @@ rstudioapi::navigateToFile("inst/htmlwidgets/frappeChart.yaml")
```

Note: keep `htmlwidgets` in `src`!

## Write the R function

**FILE:** `R/frappeChart.r`

Add appropriate arguments to `frappeChart()`.

* [title](https://frappe.io/charts/docs/reference/configuration#title)
* [type](https://frappe.io/charts/docs/reference/configuration#type)
* [colors](https://frappe.io/charts/docs/reference/configuration#colors)?
* [is_navigable](https://frappe.io/charts/docs/reference/configuration#isnavigable)

Structure the argumets into `x` and pass `...` for the "extra bits".

Rebuild the package,
then create a new R markdown document:
`js4shiny::js4shiny_doc()`.
Move the code loading `dplyr`, `tidyr`, `babynames`
and formatting the data.
Then call `frappeCharts::frappeChart()`.

Render and open dev tools in the browser to see that it "works".
Meaning that the data and dependencies are included,
but the chart won't.
Point out the random ID.
Then go back and change it so we can find the element better.


+ 22
- 0
dev/widget_demo.Rmd Dosyayı Görüntüle

@@ -0,0 +1,22 @@
---
output: js4shiny::html_document_plain
---

```{r frappeChart}
library(dplyr)
library(tidyr)
library(babynames)

data <-
babynames %>%
filter(
name %in% c("Ruth", "August"),
year >= 1980
) %>%
group_by(year, name) %>%
summarize(n = sum(n)) %>%
ungroup() %>%
pivot_wider(year, name, values_from = n)

frappeCharts::frappeChart(data, title = "This. Is. Awwesome.", elementId = "name-chart")
```

Yükleniyor…
İptal
Kaydet