From 70a022cb4b0251daf569ed656dce896d2822233d Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Tue, 26 Apr 2016 16:30:33 -0500 Subject: [PATCH] Add optional update button for bookmarkOutput --- R/restore.R | 14 ++++++++++++-- man/bookmarkOutput.Rd | 18 ++++++++++++++++++ srcjs/output_binding_bookmark.js | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 man/bookmarkOutput.Rd diff --git a/R/restore.R b/R/restore.R index c3c1e4871..98af7d52c 100644 --- a/R/restore.R +++ b/R/restore.R @@ -148,8 +148,14 @@ restoreValue <- function(id, default) { } } +#' @param id ID for the output. +#' @param label Text label, displayed above the bookmark output. +#' @param updateId An optional input ID. If non-NULL, a special actionButton +#' with this ID will be added to the input group. The purpose of this button +#' is that, when clicked, the \code{bookmarkOutput}'s value will be updated. +#' See examples below. #' @export -bookmarkOutput <- function(id, label = NULL) { +bookmarkOutput <- function(id, label = NULL, updateId = NULL) { textId <- paste0("shiny-bookmark-", id) tagList( @@ -159,9 +165,13 @@ bookmarkOutput <- function(id, label = NULL) { tags$input(id = textId, readonly = "readonly", class = "form-control", - placeholder = "Click button" + placeholder = "Bookmark URL" ), span(class = "input-group-btn", + if (!is.null(updateId)) tags$button(id = updateId, + class = "btn btn-default action-button", + icon("repeat", lib = "glyphicon") + ), tags$button(class = "btn btn-default", `data-clipboard-target` = paste0("#", textId), icon("copy", lib = "glyphicon") diff --git a/man/bookmarkOutput.Rd b/man/bookmarkOutput.Rd new file mode 100644 index 000000000..5685037d4 --- /dev/null +++ b/man/bookmarkOutput.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/restore.R +\name{bookmarkOutput} +\alias{bookmarkOutput} +\usage{ +bookmarkOutput(id, label = NULL, updateId = NULL) +} +\arguments{ +\item{id}{ID for the output.} + +\item{label}{Text label, displayed above the bookmark output.} + +\item{updateId}{An optional input ID. If non-NULL, a special actionButton +with this ID will be added to the input group. The purpose of this button +is that, when clicked, the \code{bookmarkOutput}'s value will be updated. +See examples below.} +} + diff --git a/srcjs/output_binding_bookmark.js b/srcjs/output_binding_bookmark.js index 4715d549e..2757c5d21 100644 --- a/srcjs/output_binding_bookmark.js +++ b/srcjs/output_binding_bookmark.js @@ -7,7 +7,7 @@ function renderValue(el, data) { const $el = $(el); - const $button = $el.find('button'); + const $button = $el.find('button[data-clipboard-target]'); // Initialize clipboardjs for this element, one time only if (!$button.data('clipboard-initialized')) {