router_shiny: Router server and UI

router_shinyR Documentation

Router server and UI

Description

The router_server() and router_ui() functions are used to render page modules served by a [router()] into a Shiny application.

The content for the current page will be rendered in place of router_ui(). This can appear anywhere inside the UI definition, so that common UI elements like head() tags don't need to be repeated in each page module.

router_server() can be called from anywhere inside the server() function of the Shiny application.

Usage

router_ui(id = "__router__")

router_server(router, input, output, session, id = "__router__")

Arguments

id

Router id.

router

A shinypages router() object.

input

Shiny server input object.

output

Shiny server output object.

session

Shiny server session object.

Value

router_server() returns a Shiny observer reference class object. See shiny::observe() for details.

router_ui() returns an HTML output element.

See Also

router()

Examples

if (interactive()) {

ui_test <- function(id) {
  htmltools::div(
    htmltools::p("Test!"),
    htmltools::p(htmltools::a(href = router_link("/"), "Home"))
  )
}

test_router <- router(router_page("home", ui_test))

ui <- shiny::fluidPage(
  router_ui()
)

server <- function(input, output, session) {
  router_server(test_router, input, output, session)
}

shiny::shinyApp(ui, server)
}

gorcha/shinypages documentation built on June 29, 2022, 4:38 a.m.