Skip to contents

This function creates a UI element that redirects the user to a specified URL. It can be used in both reactive and non-reactive contexts within Shiny applications.

Usage

sd_redirect(
  id,
  url,
  button = TRUE,
  label = "Click here",
  delay = NULL,
  newtab = FALSE
)

Arguments

id

A character string of a unique id to be used to identify the redirect button in the survey body.

url

A character string specifying the URL to redirect to.

button

A logical value indicating whether to create a button (TRUE) or a text element (FALSE) for the redirect. Default is TRUE.

label

A character string for the button or text label. Default is "Click here".

delay

An optional numeric value specifying the delay in seconds before automatic redirection. If NULL (default), no automatic redirection occurs.

newtab

A logical value indicating whether to open the URL in a new tab (TRUE) or in the current tab (FALSE). Default is FALSE.

Value

In a reactive context, returns a function that when called, renders the redirect element. In a non-reactive context, returns the redirect element directly.

Examples

if (FALSE) { # \dontrun{
# Basic usage with a button
sd_redirect("my_button", "https://example.com")

# Create a text link instead of a button
sd_redirect("my_link", "https://example.com", button = FALSE, label = "Visit Example")

# Add a 5-second delay before redirection
sd_redirect("delayed_redirect", "https://example.com", delay = 5)

# Open the link in a new tab
sd_redirect("new_tab_link", "https://example.com", newtab = TRUE)
} # }