Quellcode durchsuchen

htmlwidgets::scaffoldWidget("frappeChart")

master
Garrick Aden-Buie vor 6 Jahren
Ursprung
Commit
38bac2c65c
4 geänderte Dateien mit 106 neuen und 0 gelöschten Zeilen
  1. +52
    -0
      R/frappeChart.R
  2. +19
    -0
      dev/dev.Rmd
  3. +28
    -0
      inst/htmlwidgets/frappeChart.js
  4. +7
    -0
      inst/htmlwidgets/frappeChart.yaml

+ 52
- 0
R/frappeChart.R Datei anzeigen

@@ -0,0 +1,52 @@
#' <Add Title>
#'
#' <Add Description>
#'
#' @import htmlwidgets
#'
#' @export
frappeChart <- function(message, width = NULL, height = NULL, elementId = NULL) {

# forward options using x
x = list(
message = message
)

# create widget
htmlwidgets::createWidget(
name = 'frappeChart',
x,
width = width,
height = height,
package = 'frappeCharts',
elementId = elementId
)
}

#' Shiny bindings for frappeChart
#'
#' Output and render functions for using frappeChart within Shiny
#' applications and interactive Rmd documents.
#'
#' @param outputId output variable to read from
#' @param width,height Must be a valid CSS unit (like \code{'100\%'},
#' \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a
#' string and have \code{'px'} appended.
#' @param expr An expression that generates a frappeChart
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' is useful if you want to save an expression in a variable.
#'
#' @name frappeChart-shiny
#'
#' @export
frappeChartOutput <- function(outputId, width = '100%', height = '400px'){
htmlwidgets::shinyWidgetOutput(outputId, 'frappeChart', width, height, package = 'frappeCharts')
}

#' @rdname frappeChart-shiny
#' @export
renderFrappeChart <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) { expr <- substitute(expr) } # force quoted
htmlwidgets::shinyRenderWidget(expr, frappeChartOutput, env, quoted = TRUE)
}

+ 19
- 0
dev/dev.Rmd Datei anzeigen

@@ -70,4 +70,23 @@ usethis::use_build_ignore("package-lock.json")
usethis::use_git_ignore("node_modules")
```

## Scaffold the HTML widget

```{r htmlwidgets-scaffold}
htmlwidgets::scaffoldWidget("frappeChart")
```

This adds files in `inst/htmlwidgets`

```
inst
└── htmlwidgets
├── frappeChart.js #<< R <-> JS code
└── frappeChart.yaml #<< list of dependencies
```

and creates a file `R/frappeChart.R` with the functions

- `frappeChart()`
- `frappeChartOutput()` (for shiny)
- `renderFrappeChart()` (for shiny)

+ 28
- 0
inst/htmlwidgets/frappeChart.js Datei anzeigen

@@ -0,0 +1,28 @@
HTMLWidgets.widget({

name: 'frappeChart',

type: 'output',

factory: function(el, width, height) {

// TODO: define shared variables for this instance

return {

renderValue: function(x) {

// TODO: code to render the widget, e.g.
el.innerText = x.message;

},

resize: function(width, height) {

// TODO: code to re-render the widget with a new size

}

};
}
});

+ 7
- 0
inst/htmlwidgets/frappeChart.yaml Datei anzeigen

@@ -0,0 +1,7 @@
# (uncomment to add a dependency)
# dependencies:
# - name:
# version:
# src:
# script:
# stylesheet:

Laden…
Abbrechen
Speichern