Skip to contents

stage_map_output() puts a map in the user interface and render_stage_map() draws a stage_map() in it from the server. stage_map_proxy() makes the proxy that the verbs (stage_map_select(), stage_map_highlight(), stage_map_show(), stage_map_hide(), stage_map_enable() and stage_map_disable()) send their commands through, so the map changes without being drawn again.

Usage

stage_map_output(output_id, width = "100%", height = "auto")

render_stage_map(expr, env = parent.frame(), quoted = FALSE)

stage_map_proxy(
  output_id,
  session = shiny::getDefaultReactiveDomain(),
  ...,
  defer_until_flush = TRUE
)

Arguments

output_id

The output's id, as one string. In a module, give ns("map") to stage_map_output(); the proxy takes the plain "map" or the namespaced id.

width, height

The output's CSS size as text (such as "100%" or "480px") or a number of pixels; NULL is not allowed. The default height, "auto", follows the picture's content; any other height makes the output a box that scrolls inside, so a map taller than the box does not spill over what follows.

expr

An expression that gives a stage_map() widget, or NULL to show nothing. A promise of one works too.

env

The environment in which to evaluate expr.

quoted

Whether expr is already a quoted expression.

session

The Shiny session. The default is the current one, so a proxy is made inside the server function.

...

Must stay empty. It makes every argument after it a named argument.

defer_until_flush

TRUE, the default, sends a command after the outputs of the current flush, so a command sent in the same observer as a new map reaches the page after the map. FALSE sends it at once.

Value

stage_map_output() returns the HTML of the output. render_stage_map() returns a render function for an output; anything but a stage_map() widget (or NULL) is an error of class stagemap_error_widget. stage_map_proxy() returns a proxy (class stagemap_proxy) to give as map to the verbs.

Details

The map is drawn again whenever the expression of render_stage_map() gives a new map, in place. The reader's pick stays while its card is still in the new map, and is let go when the card is gone: input$map_pick then reports it with by = "data". What a verb set stays too: a card hidden, shown, disabled or enabled keeps that over what the new map says, for as long as the card is in it, and is forgotten once the card is gone (a card that comes back has the new map's own state). Lit cards from stage_map_highlight() stay lit, but only the cards and links that the new map has are lit; the ones left out are lit again if they come back. A map in a tab that is not shown yet is drawn when the tab is shown, and one inside shiny::renderUI(), shiny::insertUI(), a module or a modal works as it does anywhere else. In a module, give the output ns("map") and the proxy "map" (the plain or the namespaced id both work); the inputs below keep the module's own names, so the server reads input$map_selected.

Inputs

For an output with the id map, the server reads these inputs. A value that holds ids is a character vector, and no ids is character(0): req(input$map_selected) waits until something is selected. Until the map has been drawn in the browser, every input is NULL; input$map_pick stays NULL until the reader picks or lets go of something, or new data changes the pick.

  • input$map_selected: the ids of the selected cards, the lead (the one whose details show) last. It changes when the selection changes, whether the reader, a verb or new data changed it, and it is character(0) while nothing is selected. When the reader picks a card, input$map_pick changes in the same message, so an observer of the pick reads the new selection.

  • input$map_hovered [Experimental]: the id of the card under the pointer, or character(0) when there is none. A stage under the pointer is not reported.

  • input$map_pick: the reader's last pick, as a list of kind ("card", "stage" or "all" when the reader let go of everything; more values may be added later), id (the lead card, or the stage), ids (the picked cards, the lead last, or the stage's id), from (the id that was picked before), label, still and by ("reader", or "data" when new data changed the pick). A field with nothing to say is NULL, and ids is character(0); still is NULL, or a list of kind, id and ids for the pick that stays when the reader lets go of the other kind (a card stays picked when the stage is let go). It changes when the reader picks or lets go, and when new data changes the pick, never for a verb. Fields may be added later and none will be removed. ids belongs with kind: for a stage pick it holds the stage's id, so read the selected cards from input$map_selected.

  • input$map_state: what the map holds now, as a list of selected (the selected card ids, the lead last), stage (the chosen stage's id, or character(0)), step (the step the player shows, counting from 1; 0 at the start or without a player), highlighted (a list of ids and links, a data frame with the columns from, to and kind, with no rows when none), hidden and disabled (card ids). It changes when any of them changes. Fields may be added later and none will be removed. stage_map_highlight(proxy, state$highlighted$ids, links = state$highlighted$links) puts back what the state holds.

Bookmarking in Shiny does not save the map's selection or what a verb changed. To restore them, save input$map_selected yourself and give it to stage_map_select() when the app is restored.

See also

Other shiny: stage_map_select()

Examples

# The output goes in the user interface; it is a piece of HTML.
class(stage_map_output("map", "100%", "480px"))
#> [1] "shiny.tag.list" "list"          
if (FALSE) { # interactive()
library(shiny)
cards <- data.frame(
  id = c("draft", "review", "publish"),
  label = c("Draft", "Review", "Publish"),
  stage = c("write", "check", "ship"),
  lane = "docs"
)
ui <- fluidPage(
  stage_map_output("map", height = "420px"),
  verbatimTextOutput("picked"),
  actionButton("publish", "Select Publish")
)
server <- function(input, output, session) {
  output$map <- render_stage_map(
    stage_map(cards, title = "A small piece of work") |>
      add_links(data.frame(from = c("draft", "review"), to = c("review", "publish")))
  )
  output$picked <- renderPrint(input$map_selected)
  observeEvent(input$publish, {
    stage_map_proxy("map") |> stage_map_select("publish")
  })
}
shinyApp(ui, server)
}