Learn R Programming

dash (version 0.9.4)

dccLocation: Location component

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

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

Run this code
# NOT RUN {
if (interactive()) {
    library(dash)

    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()
}
# }

Run the code above in your browser using DataLab