Used to construct a multi-page modal dialog. Next and Back buttons are used to navigate the pages sequentially. Optional validation functions may be specified for each page. A callback function may be specified to obtain the user's inputs.
slatesModalMultiPage( id, session, pages.ui, submit.fun, validators = NULL, back.button = TRUE, default.size = c("m", "s", "l", "xl"), observers = list() )
id | dialog id |
---|---|
session | shiny server session |
pages.ui | a list of functions, each used to build a page. These functions
may define any number of arguments used to build the page's UI. The return value
of these functions should be a valid |
submit.fun | a function that returns the results of the user interaction with the modal dialog. The return value should be a list with named elements. |
validators | a list of functions used to validate the state of each page. A
user may not proceed to the next page of the modal dialog until the validator function
for the current page returns |
back.button | whether or not to show the back button on the modal's pages. |
observers | a list containing any number of observers. This is used solely to allow the modal dialog to destroy the observers when it is destroyed. |
size | default width of the modal dialog. One of "s", "m", "l", "xl". Note that
the |
A list containing the modal id and the show()
function (see details below).
After creating the modal dialog, the show
function is used to display it. This
function takes in a mandatory callback
argument, and optional title
. When the user
exits the dialog by pressing the OK button, the provided callback
function is called
with each argument named as an element of the result from submit.fun
. Additional
arguments provided to the show
method will be passed on to the UI definition
functions provided in pages.ui
. See example below.
if (interactive()) { exampleMultiPageModal <- function(id, session) { ID <- function(x) paste0(id, "_", x) ns <- session$ns input <- session$input pages.ui <- list( function(common.label, text.value = "") { tagList( helpText("Hello there! This is page 1! Please enter less than 5 characters."), textInput(ns(ID("text_input")), label = common.label, value = text.value) ) }, function(common.label, numeric.value) { tagList( helpText("Hi again! We're on page 2 now. Enter 42 below."), numericInput(ns(ID("numeric_input")), label = common.label, value = numeric.value) ) } ) submit.fun <- function() { list(text.value = session$input[[ ID("text_input") ]], numeric.value = session$input[[ ID("numeric_input") ]]) } validators <- list( function() { return(nchar(input[[ ID("text_input") ]]) < 5) }, function() { return(input[[ ID("numeric_input") ]] == 42) } ) slatesModalMultiPage(id, session, pages.ui = pages.ui, submit.fun = submit.fun, validators = validators) } app <- shinyApp( ui = fluidPage( shinyjs::useShinyjs(), actionButton("show", "Show Modal") ), server = function(input, output, session) { modal <- exampleMultiPageModal("modal", session) observeEvent(input$show, { modal$show( common.label = "Some input", text.value = "Something", numeric.value = 41, title = "Example Multi-Page Modal", callback = function(text.value, numeric.value) { print(paste("Modal returned:", text.value, ",", numeric.value)) } ) }) } ) runApp(app) }