Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shiny API v2 - modern aliases for Shiny UI/output functions #1077

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4134ecf
feat: input_action_button
gadenbuie Jun 14, 2024
beeba25
feat: input_action_link
gadenbuie Jun 14, 2024
a6ea91e
feat: input_select
gadenbuie Jun 14, 2024
7d08ead
feat: input_selectize
gadenbuie Jun 14, 2024
84b742c
feat: input_slider
gadenbuie Jun 14, 2024
1921882
feat: input_date
gadenbuie Jun 14, 2024
b3aa6dd
feat: input_date_range
gadenbuie Jun 14, 2024
cdda099
feat: input_checkbox
gadenbuie Jun 14, 2024
fb2bc93
feat: input_checkbox_group
gadenbuie Jun 14, 2024
d43a463
feat: input_radio_buttons
gadenbuie Jun 14, 2024
b41a7e2
feat: input_numeric, input_text, input_text_area, input_password
gadenbuie Jun 14, 2024
97d2d4b
docs: improve param inheriting in update functions
gadenbuie Jun 14, 2024
7cf9152
docs: Add note calling out the aliasing
gadenbuie Jun 14, 2024
552ad0b
docs: add to pkgdown index
gadenbuie Jun 14, 2024
139a013
docs: Use "Aliased from Shiny" instead of note
gadenbuie Jun 14, 2024
962940d
Add seealso links to connect inputs to updaters
gadenbuie Jun 14, 2024
daf8625
feat: Aliases for output and render functions
gadenbuie Jun 14, 2024
2287726
docs: Move Shiny aliases after theming section in reference
gadenbuie Jun 14, 2024
c52d0d9
docs: tweak aliases callout
gadenbuie Jun 14, 2024
ee7f9d6
feat: input_file
gadenbuie Jun 14, 2024
3a8bbf6
feat: download_button, download_link, download_handler
gadenbuie Jun 14, 2024
00fae70
fix: render_* functions
gadenbuie Jun 15, 2024
080c1e6
Resave data (GitHub Action)
gadenbuie Jun 15, 2024
37be7dd
docs: Document output `id`
gadenbuie Jun 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,30 @@ Collate:
'popover.R'
'precompiled.R'
'print.R'
'shiny-aliases.R'
'shiny-devmode.R'
'shiny-download_button.R'
'shiny-input_action_button.R'
'shiny-input_action_link.R'
'shiny-input_checkbox.R'
'shiny-input_checkbox_group.R'
'shiny-input_date.R'
'shiny-input_date_range.R'
'shiny-input_file.R'
'shiny-input_numeric.R'
'shiny-input_password.R'
'shiny-input_radio_buttons.R'
'shiny-input_select.R'
'shiny-input_selectize.R'
'shiny-input_slider.R'
'shiny-input_text.R'
'shiny-input_text_area.R'
'shiny-output_image.R'
'shiny-output_plot.R'
'shiny-output_table.R'
'shiny-output_text.R'
'shiny-output_text_verbatim.R'
'shiny-output_ui.R'
'sidebar.R'
'staticimports.R'
'tooltip.R'
Expand Down
43 changes: 43 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,31 @@ export(card_footer)
export(card_header)
export(card_image)
export(card_title)
export(download_button)
export(download_handler)
export(download_link)
export(font_collection)
export(font_face)
export(font_google)
export(font_link)
export(input_action_button)
export(input_action_link)
export(input_checkbox)
export(input_checkbox_group)
export(input_dark_mode)
export(input_date)
export(input_date_range)
export(input_file)
export(input_numeric)
export(input_password)
export(input_radio_buttons)
export(input_select)
export(input_selectize)
export(input_slider)
export(input_switch)
export(input_task_button)
export(input_text)
export(input_text_area)
export(is.card_item)
export(is_bs_theme)
export(is_fill_carrier)
Expand Down Expand Up @@ -120,6 +138,12 @@ export(navset_pill)
export(navset_pill_list)
export(navset_tab)
export(navset_underline)
export(output_image)
export(output_plot)
export(output_table)
export(output_text)
export(output_text_verbatim)
export(output_ui)
export(page)
export(page_fill)
export(page_fillable)
Expand All @@ -130,6 +154,12 @@ export(page_sidebar)
export(popover)
export(precompiled_css_path)
export(remove_all_fill)
export(render_image)
export(render_plot)
export(render_table)
export(render_text)
export(render_text_verbatim)
export(render_ui)
export(run_with_themer)
export(showcase_bottom)
export(showcase_left_center)
Expand All @@ -144,9 +174,22 @@ export(toggle_sidebar)
export(toggle_switch)
export(toggle_tooltip)
export(tooltip)
export(update_action_button)
export(update_action_link)
export(update_checkbox)
export(update_checkbox_group)
export(update_date)
export(update_date_range)
export(update_numeric)
export(update_popover)
export(update_radio_buttons)
export(update_select)
export(update_selectize)
export(update_slider)
export(update_switch)
export(update_task_button)
export(update_text)
export(update_text_area)
export(update_tooltip)
export(value_box)
export(value_box_theme)
Expand Down
26 changes: 26 additions & 0 deletions R/shiny-aliases.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
docs_callout_shiny_alias <- function(new, old) {
sprintf(
paste0(
"This function is an alias for `shiny::%s()` and is included to ",
"maintain more consistent naming conventions in Shiny apps that use ",
"\\pkg{bslib}. The documentation on this page may still refer to the ",
"original function names. You can replace `shiny::%s()` with `%s()`."
),
old, old, new
)
}

shiny_quote_if_unquoted <- function(
expr,
quoted = FALSE,
...,
env = parent.frame()
) {
if (quoted) return(expr)
# installExprFunction() quotes using its parent.frame(), which will not be
# the right frame when `shiny::renderPrint()` or similar are called from
# within a wrapping function. This function is a workaround to quote the
# expression, in the right environment, so that we always pass quoted
# expressions to `shiny::renderPrint()`.
eval(substitute(substitute(expr)), env)
}
69 changes: 69 additions & 0 deletions R/shiny-download_button.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#' @inherit shiny::downloadButton params return title description details sections references
#'
#' @inheritParams input_action_button
#'
#' @section Aliased from Shiny: `r docs_callout_shiny_alias("download_button", "downloadButton")`
#'
#' @family Shiny upload/download aliases
#' @export
download_button <- function(
id,
label = "Download",
...,
class = NULL,
icon = shiny::icon("download")
) {
shiny::downloadButton(
outputId = id,
label = "Download",
class = NULL,
...,
icon = shiny::icon("download")
)
}

#' @inherit shiny::downloadLink params return title description details sections references
#'
#' @inheritParams input_action_button
#'
#' @section Aliased from Shiny: `r docs_callout_shiny_alias("download_link", "downloadLink")`
#'
#' @family Shiny upload/download aliases
#' @export
download_link <- function(
id,
label = "Download",
...,
class = NULL
) {
shiny::downloadLink(
outputId = id,
label = "Download",
class = NULL,
...
)
}

#' @inherit shiny::downloadHandler params return title description details sections references
#'
#' @section Aliased from Shiny: `r docs_callout_shiny_alias("download_handler", "downloadHandler")`
#'
#' @seealso
#' * [download_button()] creates a download button in the UI.
#' * [download_link()] creates a download link in the UI.
#'
#' @family Shiny upload/download aliases
#' @export
download_handler <- function(
filename,
content,
contentType = NULL,
outputArgs = list()
) {
shiny::downloadHandler(
filename = filename,
content = content,
contentType = contentType,
outputArgs = outputArgs
)
}
56 changes: 56 additions & 0 deletions R/shiny-input_action_button.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#' @inherit shiny::actionButton params return title description details sections references
#'
#' @param id An input id.
#' @param label An input label.
#'
#' @section Aliased from Shiny: `r docs_callout_shiny_alias("input_action_button", "actionButton")`
#'
#' @seealso [update_action_button()] to programmatically update an action
#' button.
#'
#' @family Shiny input aliases
#' @export
input_action_button <- function(
id,
label,
...,
icon = NULL,
width = NULL,
disabled = FALSE
) {
shiny::actionButton(
inputId = id,
label = list(icon, label), # avoid shiny's icon validation
width = width,
disabled = disabled,
...
)
}

#' @inherit shiny::updateActionButton params return title description details sections references
#' @inheritParams input_action_button
#'
#' @inheritParams input_action_button
#' @param ... Ignored, included for future expansion.
#'
#' @section Aliased from Shiny: `r docs_callout_shiny_alias("update_action_button", "updateActionButton")`
#'
#' @seealso [input_action_button()] to create an action button.
#'
#' @family Shiny update aliases
#' @export
update_action_button <- function(
id,
...,
label = NULL,
icon = NULL,
disabled = NULL,
session = get_current_session()
) {
# In-lined to avoid shiny's icon validation
validate_session_object(session, "update_action_button")

if (!is.null(icon)) icon <- as.character(icon)
message <- dropNulls(list(label=label, icon=icon, disabled=disabled))
session$sendInputMessage(id, message)
}
47 changes: 47 additions & 0 deletions R/shiny-input_action_link.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#' @inherit shiny::actionLink params return title description details sections references
#'
#' @inheritParams input_action_button
#'
#' @section Aliased from Shiny: `r docs_callout_shiny_alias("input_action_link", "actionLink")`
#'
#' @seealso [update_action_link()] to programmatically update an action link.
#'
#' @family Shiny input aliases
#' @export
input_action_link <- function(
id,
label,
icon = NULL,
...
) {
shiny::actionLink(
inputId = id,
label = list(icon, label), # avoid shiny's icon validation
...
)
}

#' @inherit shiny::updateActionLink params return title description details sections references
#' @inheritParams input_action_button
#' @param ... Ignored, included for future expansion.
#'
#' @section Aliased from Shiny: `r docs_callout_shiny_alias("update_action_link", "updateActionLink")`
#'
#' @seealso [input_action_link()] to create an action link.
#'
#' @family Shiny update aliases
#' @export
update_action_link <- function(
id,
...,
label = NULL,
icon = NULL,
session = get_current_session
) {
update_action_button(
id = id,
label = label,
icon = icon,
session = session
)
}
51 changes: 51 additions & 0 deletions R/shiny-input_checkbox.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#' @inherit shiny::checkboxInput params return title description details sections references
#'
#' @inheritParams input_action_button
#' @param ... Ignored, included for future expansion.
#'
#' @seealso [update_checkbox()] to programmatically update a checkbox.
#'
#' @section Aliased from Shiny: `r docs_callout_shiny_alias("input_checkbox", "checkboxInput")`
#'
#' @family Shiny input aliases
#' @export
input_checkbox <- function(
id,
label,
value = FALSE,
...,
width = NULL
) {
shiny::checkboxInput(
inputId = id,
label = label,
value = value,
width = width
)
}

#' @inherit shiny::updateCheckboxInput params return title description details sections references
#'
#' @inheritParams input_action_button
#' @param ... Ignored, included for future expansion.
#'
#' @seealso [input_checkbox()] to create a checkbox.
#'
#' @section Aliased from Shiny: `r docs_callout_shiny_alias("update_checkbox", "updateCheckboxInput")`
#'
#' @family Shiny update aliases
#' @export
update_checkbox <- function(
id,
...,
label = NULL,
value = NULL,
session = get_current_session()
) {
shiny::updateCheckboxInput(
session = session,
inputId = id,
label = label,
value = value
)
}
Loading
Loading