{brochure}: multipage {shiny} apps, now on CRAN

Author : Colin Fay
Categories : golem, shiny
Tags :
Date :

A {shiny} app is a single page: one url, one UI, one server function. That is comfortable while the app stays small. As soon as you want an actual site — a home page, a contact page, one page per user, urls people can bookmark or send by email — you end up faking pages with tabs and conditionalPanel().

{brochure} takes the problem the other way around: every page is a real page, with its own url, its own UI, its own server function and its own Shiny session.

install.packages("brochure")
library(shiny)
library(brochure)

brochureApp(
  page(
    href = "/",
    ui = fluidPage(
      h1("Home"),
      tags$a(href = "/contact", "Contact us")
    ),
    server = function(input, output, session) {
      # ...
    }
  ),
  page(
    href = "/contact",
    ui = fluidPage(h1("Contact"))
  )
)

You run it as you would any Shiny app, and moving from one page to another is a plain link. A url can also carry a parameter — /user/:id, which the page reads back with get_keys().

Around that, {brochure} gives you what you expect from a web server: request and response handlers to log, serve a healthcheck or answer before Shiny ever runs, helpers to set and read cookies (and so carry state from one page to the next), redirections, and what it takes to serve the app behind a reverse proxy or on Posit Connect.

The trade-off: you leave the single page paradigm behind, and nothing computed on one page survives a navigation to another. That is what vignette("design") is about — worth reading before you start.

The full post, with examples and what this release brings:

👉 {brochure} 1.0.0 is now on CRAN

Documentation: colinfay.me/brochure.


Comments


Also read