Преглед изворни кода

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 Прегледај датотеку

#' @import htmlwidgets #' @import htmlwidgets
#' #'
#' @export #' @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 # forward options using x
x = list( x = list(
message = message
title = title,
type = match.arg(type),
height = height,
data = data,
isNavigable = is_navigable,
...
) )


# create widget # create widget

+ 28
- 0
dev/dev.Rmd Прегледај датотеку

``` ```


Note: keep `htmlwidgets` in `src`! 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 Прегледај датотеку

---
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…
Откажи
Сачувај