knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
shinypages is a simple multi-page router for Shiny applications, very much inspired by Appsilon's shiny.router.
You can install the development version of shinypages like so:
# install.packages("devtools") devtools::install_github("gorcha/shinypages")
library(shiny) library(shinypages) # Create a simple page with only UI ui_home <- function(id) { tagList( h2("Hello world!"), p(a(href = router_link("cars"), "Cars")), p(a(href = router_link("admin"), "Admin")) ) } home_page <- router_page("home", ui_home) # Create a page with UI and a module server ui_cars <- function(id) { ns <- NS(id) tagList( h2("Cars"), p(a(href = router_link("home"), "Home")), tableOutput(ns("cars")) ) } server_cars <- function(id) { moduleServer(id, function(input, output, session) { output$cars <- renderTable(mtcars) }) } cars_page <- router_page("cars", ui_cars, server_cars) # Restrict access to a page is_admin <- function(session) { "admin" %in% session$groups } ui_admin <- function(id) { tagList( h2("Top Secret"), p(a(href = router_link("home"), "Home")) ) } admin_page <- router_page("admin", ui_admin, authorised = is_admin) # Create a router my_router <- router(home_page, cars_page, admin_page) # Add your router into a Shiny application ui <- fixedPage( router_ui() ) server <- function(input, output, session) { router_server(my_router, input, output, session) } shinyApp(ui, server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.