Learn R Programming

dash (version 0.1.0)

Dash: Create and configure a Dash app object

Description

A framework for building analytical web applications, Dash offers a pleasant and productive development experience. No JavaScript required.

Usage

Dash

Format

An R6::R6Class generator object

Constructor

Dash$new( name = "dash", server = fiery::Fire$new(), assets_folder = 'assets', assets_url_path = '/assets', assets_ignore = '', serve_locally = TRUE, routes_pathname_prefix = '/', requests_pathname_prefix = '/' )

Arguments

name Character. The name of the Dash application (placed in the <title> of the HTML page).
server The web server used to power the application. Must be a fiery::Fire object.
assets_folder Character. A path, relative to the current working directory, for extra files to be used in the browser. Default is "assets". All .js and .css files will be loaded immediately unless excluded by assets_ignore, and other files such as images will be served if requested. Default is assets.
assets_url_path Character. Specify the URL path for asset serving. Default is assets.
assets_ignore Character. A regular expression, to match assets to omit from immediate loading. Ignored files will still be served if specifically requested. You cannot use this to prevent access to sensitive files.
serve_locally Whether to serve HTML dependencies locally or remotely (via URL).
routes_pathname_prefix a prefix applied to the backend routes.
requests_pathname_prefix a prefix applied to request endpoints made by Dash's front-end.
external_scripts An optional list of valid URLs from which to serve JavaScript source for rendered pages.
external_stylesheets An optional list of valid URLs from which to serve CSS for rendered pages.
suppress_callback_exceptions Whether to relay warnings about possible layout mis-specifications when registering a callback.

Fields

server

A cloned (and modified) version of the fiery::Fire object provided to the server argument (various routes will be added which enable Dash functionality).

config

A list of configuration options passed along to dash-renderer. Users shouldn't need to alter any of these options unless they are constructing their own authorization front-end or otherwise need to know where the application is making API calls.

Methods

layout(...)

Set the layout (i.e., user interface). The layout should be either a collection of Dash components (e.g., dccSlider, htmlDiv, etc) or a function which returns a collection of components.

layout_get(render = TRUE)

Retrieves the layout. If render is TRUE, and the layout is a function, the result of the function (rather than the function itself) is returned.

callback(output, params, func)

The callback method has three formal arguments:

output

a named list including a component id and property

params

an unnamed list of input and state statements, each with defined id and property

func

any valid R function which generates output provided input and/or state arguments

The output argument defines which layout component property should receive the results (via the output object). The events that trigger the callback are then described by the input (and/or state) object(s) (which should reference layout components), which become argument values for the callback handler defined in func.

run_server(host = Sys.getenv('DASH_HOST', "127.0.0.1"), port = Sys.getenv('DASH_PORT', 8050), block = TRUE, showcase = FALSE, ...)

Launch the application. If provided, host/port set the host/port fields of the underlying fiery::Fire web server. The block/showcase/... arguments are passed along to the ignite() method of the fiery::Fire server.

Examples

Run this code
# NOT RUN {
library(dash)
app <- Dash$new()
app$layout(
 dccInput(id = "inputID", value = "initial value", type = "text"),
 htmlDiv(id = "outputID")
)

app$callback(output = list(id="outputID", property="children"),
             params = list(input(id="inputID", property="value"),
                      state(id="inputID", property="type")),
  function(x, y)
    sprintf("You've entered: '%s' into a '%s' input control", x, y)
)

app$run_server(showcase = TRUE)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab