dccLocation: Location component

Description Usage Arguments Value Examples

View source: R/dccLocation.R

Description

Update and track the current window.location object through the window.history state. Use in conjunction with the 'dash_core_components.Link' component to make apps with multiple pages.

Usage

1
2
dccLocation(id=NULL, pathname=NULL, search=NULL, hash=NULL, href=NULL,
refresh=NULL)

Arguments

id

Character. The ID of this component, used to identify dash components in callbacks. The ID needs to be unique across all of the components in an app.

pathname

Character. pathname in window.location - e.g., "/my/full/pathname"

search

Character. search in window.location - e.g., "?myargument=1"

hash

Character. hash in window.location - e.g., "#myhash"

href

Character. href in window.location - e.g., "/my/full/pathname?myargument=1#myhash"

refresh

Logical. Refresh the page when the location is updated?

Value

named list of JSON elements corresponding to React.js properties and their values

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
if (interactive() && require(dash)) {
    library(dash)
    library(dashCoreComponents)
    library(dashHtmlComponents)

    app <- Dash$new()

    app$layout(htmlDiv(list(
              # represents the URL bar, doesn't render anything
              dccLocation(id = 'url', refresh=FALSE),
              dccLink('Navigate to "/"', href='/'),
              htmlBr(),
              dccLink('Navigate to "/page-2"', href='/page-2'),

              # content will be rendered in this element
              htmlDiv(id='page-content')
            )
        )
    )

    app$callback(output=list(id='page-content', property='children'),
                params=list(
              input(id='url', property='pathname')),
              function(pathname)
              {
              paste0('You are on page ', pathname)
              }
    )

  app$run_server()
}

dashCoreComponents documentation built on July 1, 2020, 8:20 p.m.