router | R Documentation |
A router()
defines a multi-page Shiny application using a set of
router_page()
s. See router_server()
and router_ui()
to create a
multi-page application from the returned router
object.
router( ..., callback_pageload = NULL, callback_default = NULL, page_403 = router_page("403", ui_403), page_404 = router_page("404", ui_404) ) ## S3 method for class 'router' print(x, short = FALSE, ...)
... |
A set of |
callback_pageload |
A function that is called immediately after page
content is rendered. The function should take a |
callback_default |
A function that determines the default page. The function should take a shiny session as input and return the path of the default page. If not provided, the first page is used as the default. |
page_403 |
A |
page_404 |
A |
x |
A |
short |
Should a one line summary be printed? |
A router
object.
The callback function arguments allow user customisation of the page serving process.
callback_pageload
is called after a new page is loaded. It should be a
function with the signature function(page, session)
, taking a router_page
and a shiny session as input. Thh return value of the function is ignored.
Useful to perform operations based on page metadata.
callback_pageload = function(page, session) { shinyjs::runjs(paste0("document.title = \"", page$title, "\";")) }
callback_default()
is called to determine the path to serve when the
default page is requested. It should be a function with the signature
function(session)
, taking a shiny session as input and returning the path
of the page to load.
Useful for setting per-user or per-group home pages.
callback_default = function(session) { if ("dev" %in% session$groups) { "devlanding" } else { "home" } }
router_page
s are served in place of common HTTP response codes. These can
be customised:
page_403
is served when the authorised
function of a page returns
FALSE
.
page_404
is served when an unknown path is requested.
router_page()
to create pages, add_router_callback()
to add
callback functions to an existing router, and router_server()
and
router_ui()
to add a router to a Shiny application.
if (interactive()) { ui_test <- function(id) { htmltools::p("Test!") } home_page <- router_page("home", ui_test) other_page - router_page("other", ui_test) test_router <- router(home_page, other_page) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.