Преглед на файлове

Complete R function

master
Garrick Aden-Buie преди 6 години
родител
ревизия
cbc25a8f7b
променени са 3 файла, в които са добавени 66 реда и са изтрити 2 реда
  1. +16
    -2
      R/frappeChart.R
  2. +28
    -0
      dev/dev.Rmd
  3. +22
    -0
      dev/widget_demo.Rmd

+ 16
- 2
R/frappeChart.R Целия файл

@@ -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 Целия файл

@@ -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 Целия файл

@@ -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")
```

Loading…
Отказ
Запис