Package 'brochure'

Title: Multipage 'Shiny' Apps
Description: Build multipage 'shiny' apps.
Authors: Colin Fay [aut, cre]
Maintainer: Colin Fay <[email protected]>
License: MIT + file LICENSE
Version: 0.0.0.9024
Built: 2024-09-20 02:54:26 UTC
Source: https://github.com/ColinFay/brochure

Help Index


Create a brochureApp

Description

This function is to be used in place of shinyApp().

Usage

brochureApp(
  ...,
  onStart = NULL,
  options = list(),
  enableBookmarking = NULL,
  content_404 = "Not found",
  basepath = "",
  req_handlers = list(),
  res_handlers = list(),
  wrapped = shiny::tagList
)

Arguments

...

a list of elements to inject in the brochureApp. IMPORTANT NOTE all elements which are not of class "brochure_*" will be injected as is in the page. In other word, if you use a function that return a string, the string will be added as is to the pages. The only elements that should be injected on top of page()s are HTML elements and/or tagList/tags that are invisible on screen (for example a ⁠<script></script>⁠).

onStart

A function that will be called before the app is actually run. This is only needed for shinyAppObj, since in the shinyAppDir case, a global.R file can be used for this purpose.

options

Named options that should be passed to the runApp call (these can be any of the following: "port", "launch.browser", "host", "quiet", "display.mode" and "test.mode"). You can also specify width and height parameters which provide a hint to the embedding environment about the ideal height/width for the app.

enableBookmarking

Can be one of "url", "server", or "disable". The default value, NULL, will respect the setting from any previous calls to enableBookmarking(). See enableBookmarking() for more information on bookmarking your app.

content_404

The content to dislay when a 404 is sent

basepath

The base path of your app. This pattern will be removed from the url, so that it matches the href of your page(). For example, it you have an app at ⁠http://connect.thinkr.fr/brochure/⁠, and your page is names page1, use basepath = "brochure"

req_handlers

a list of functions that can manipulate the req object. These functions should take req as a parameters, and return the req object (potentially modified), or an object of class httpResponse. If any of the req_handlers return an httpResponse, this response will be sent to the browser immeditately, stopping any other code.

res_handlers

A list of functions that can manipulate the httpResponse object before it is send to the browser. Each function must take a res and req parameter.

wrapped

A UI function wrapping the Brochure UI. Default is shiny::tagList.

Value

A shiny.appobj


Golem Hook function

Description

Golem Hook function

Usage

golem_hook(path, package_name, ...)

Arguments

path

Name of the folder to create the package in. This will also be used as the package name.

package_name

Package name to use. By default, golem uses basename(path). If path == '.' & package_name is not explicitly set, then basename(getwd()) will be used.

...

Arguments passed from create_golem(), unused in the default function.

Value

Used for side effect

Examples

if (requireNamespace("golem") & interactive()) {
  golem::create_golem("myapp", project_hook = golem_hook)
}

Add page

Description

Module template for golem

Usage

new_page(name, path, export, ...)

Arguments

name

The name of the module.

path

The path to the R script where the module will be written. Note that this path will not be set by the user but via add_module().

export

Should the module be exported? Default is FALSE.

...

Arguments to be passed to the module_template function.

Value

Used for side effect

Examples

if (requireNamespace("golem") & interactive()) {
  golem::add_module(name = "home", module_template = brochure::new_page)
}

A Brochure Page

Description

A Brochure Page

Usage

page(
  href,
  ui = tagList(),
  server = function(input, output, session) {
 },
  req_handlers = list(),
  res_handlers = list()
)

Arguments

href

The endpoint to serve the UI on

ui

The UI definition of the app (for example, a call to fluidPage() with nested controls).

If bookmarking is enabled (see enableBookmarking), this must be a single argument function that returns the UI definition.

server

A function with three parameters: input, output, and session. The function is called once for each session ensuring that each app is independent.

req_handlers

a list of functions that can manipulate the req object. These functions should take req as a parameters, and return the req object (potentially modified), or an object of class httpResponse. If any of the req_handlers return an httpResponse, this response will be sent to the browser immeditately, stopping any other code.

res_handlers

A list of functions that can manipulate the httpResponse object before it is send to the browser. Each function must take a res and req parameter.

Value

A list

Examples

library(shiny)
page(
  href = "/page2",
  ui = tagList(
    h1("This is my second page"),
    plotOutput("plotb")
  )
)

Parse the cookie string

Description

Parse the cookie string

Usage

parse_cookie_string(cookie_string)

get_cookies(session = shiny::getDefaultReactiveDomain())

Arguments

cookie_string

The cookie string to parse

session

The {shiny} session object.

Value

a list of cookies and values

Examples

parse_cookie_string("brochure_session=63422; brochure_cookie=3958")

Redirection

Description

Redirection

Usage

redirect(from, to, code = 301)

Arguments

from

redirect from

to

redirect to

code

redirectin http code (one of c(301:308, 310))

Value

A redirection


Do a server side redirection

Description

Do a server side redirection

Usage

server_redirect(to, session = shiny::getDefaultReactiveDomain())

Arguments

to

the destination of the redirection

session

shiny session object, default is shiny::getDefaultReactiveDomain()