dccLocation: Location component

View source: R/dashCoreComponents.R

dccLocationR Documentation

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

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

plotly/dashR documentation built on Oct. 13, 2024, 6:57 a.m.