Skip to content

Need a mechanism to inline Dash for R examples within generated package help #831

@rpkyle

Description

@rpkyle

It is customary to provide sample code within R's native documentation which is executable at package build time. This is helpful to package users looking for a quick demo for functions in packages, but also to developers wanting to demonstrate packages work as expected.

Repositories such as CRAN require this to be present, although their current automated package checks pass when a vignette exists.

To avoid delays for future submissions, and to streamline the path for Dash component developers, we should introduce functionality which allows for easy inlining of function examples.

The dash-info.yaml file is a logical avenue to implement this feature. If this file exists, and if it contains examples, we should insert them at the end of the corresponding .Rd file, e.g.

r_examples:
    - name: df_to_list
      dontrun: TRUE
      code: |
           # first, create data frame
           df <- read.csv(url(
                  'https://raw.githubusercontent.com/plotly/datasets/master/solar.csv'
               ),
              check.names=FALSE,
              stringsAsFactors=FALSE
           )
           # then convert to list-of-lists format for use in dashTable
           # the following snippet below will print as JSON
           # see the help for dashDataTable to see an actual app example
           dashDataTable(
                  id = 'table',
                  columns = lapply(colnames(df), function(x) {
                         list(name = x, id = x)
                  }),
                  data = df_to_list(df)
           )

...should generate the following .Rd markup:

\examples{
\dontrun{
           # first, create data frame
           df <- read.csv(url(
                  'https://raw.githubusercontent.com/plotly/datasets/master/solar.csv'
               ),
              check.names=FALSE,
              stringsAsFactors=FALSE
           )
           # then convert to list-of-lists format for use in dashTable
           # the following snippet below will print as JSON
           # see the help for dashDataTable to see an actual app example
           dashDataTable(
                  id = 'table',
                  columns = lapply(colnames(df), function(x) {
                         list(name = x, id = x)
                  }),
                  data = df_to_list(df)
           )}
}

@alexcjohnson @Marc-Andre-Rivet

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions