Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Dec 4, 2024
1 parent 5afa0fb commit 7c11d90
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 41 deletions.
24 changes: 24 additions & 0 deletions R/shiny.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#' Shiny bindings for uPlot
#'
#' Output and render functions for using uPlot within Shiny
#' applications and interactive Rmd documents.
#'
#' @inheritParams htmlwidgets::shinyWidgetOutput
#'
#' @name uPlot-shiny
#'
#' @importFrom htmlwidgets shinyWidgetOutput shinyRenderWidget
#'
#' @export
uPlotOutput <- function(outputId, width = "100%", height = "400px") {
htmlwidgets::shinyWidgetOutput(outputId, "uPlot", width, height, package = "uPlot")
}

#' @inheritParams htmlwidgets::shinyRenderWidget
#' @rdname uPlot-shiny
#' @export
renderUPlot <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) { expr <- substitute(expr) } # force quoted
htmlwidgets::shinyRenderWidget(expr, uPlotOutput, env, quoted = TRUE)
}
2 changes: 1 addition & 1 deletion R/uBands.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @return An `htmlwidget` object of class `"uPlot"`.
#' @export
#'
#' @examples
#' @example examples/ex-uBands.R
uBands <- function(uplot, lower, upper, fill, ...) {
check_uplot(uplot)
stopifnot(
Expand Down
40 changes: 7 additions & 33 deletions R/uPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
#' )
#' )
uPlot <- function(data,
options = list(),
options = list(),
...,
use_gzipped_json = FALSE,
width = NULL,
height = NULL,
width = NULL,
height = NULL,
elementId = NULL) {

options <- as.list(options)
Expand All @@ -48,7 +48,10 @@ uPlot <- function(data,
}
if (is.null(options$series)) {
strokes <- rep_len(palette(), length(series_nms))
options$series <- prepare_options_series(label = series_nms, stroke = strokes)
options$series <- prepare_options_series(
label = series_nms,
stroke = strokes
)
}
if (is.null(options$bands)) {
options$bands <- list()
Expand Down Expand Up @@ -87,32 +90,3 @@ uPlot <- function(data,
)
}

#' Shiny bindings for uPlot
#'
#' Output and render functions for using uPlot within Shiny
#' applications and interactive Rmd documents.
#'
#' @param outputId output variable to read from
#' @param width,height Must be a valid CSS unit (like \code{'100\%'},
#' \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a
#' string and have \code{'px'} appended.
#' @param expr An expression that generates a uPlot
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' is useful if you want to save an expression in a variable.
#'
#' @name uPlot-shiny
#'
#' @importFrom htmlwidgets shinyWidgetOutput shinyRenderWidget
#'
#' @export
uPlotOutput <- function(outputId, width = '100%', height = '400px'){
htmlwidgets::shinyWidgetOutput(outputId, 'uPlot', width, height, package = 'uPlot')
}

#' @rdname uPlot-shiny
#' @export
renderUPlot <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) { expr <- substitute(expr) } # force quoted
htmlwidgets::shinyRenderWidget(expr, uPlotOutput, env, quoted = TRUE)
}
4 changes: 2 additions & 2 deletions examples/scatter.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ uPlot::uPlot(
),
series = list(
list(),
list(stroke = "#DF010180", paths = htmlwidgets::JS("drawPoints")) ,
list(stroke = "#0431B480", paths = htmlwidgets::JS("drawPoints"))
list(label = "A", stroke = "#DF010180", paths = htmlwidgets::JS("drawPoints")) ,
list(label = "B", stroke = "#0431B480", paths = htmlwidgets::JS("drawPoints"))
)
)
)
12 changes: 12 additions & 0 deletions man/uBands.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions man/uPlot-shiny.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7c11d90

Please sign in to comment.