R/shiny.R

Defines functions eChartOutput renderEChart

Documented in eChartOutput renderEChart

#' Wrapper functions for Shiny
#'
#' Use \code{eChartOutput()} to create a container for a ECharts widget in the
#' UI, and \code{renderEChart()} to render the widget on the server side.
#' @param outputId the output id to be used in the \code{output} object on the
#'   server side
#' @param width the width of the chart
#' @param height the height of the chart
#' @rdname recharts-shiny
#' @export
#' @examples # !formatR
#' \donttest{library(recharts)
#' library(shiny)
#' app = shinyApp(
#'   ui = fluidPage(eChartOutput('myChart')),
#'   server = function(input, output) {
#'     chart = echart(data.frame(x = rnorm(100), y = rnorm(100)), x, y)
#'     output$myChart = renderEChart(chart)
#'   }
#' )
#'
#' if (interactive()) print(app)}
eChartOutput = function(outputId, width = '100%', height = '100%') {
    htmlwidgets::shinyWidgetOutput(outputId, 'echarts', width, height,
                                   package = 'recharts2')
}

#' @param expr an R expression to return an EChart widget
#' @inheritParams htmlwidgets::shinyRenderWidget
#' @rdname recharts-shiny
#' @export
renderEChart = function(expr, env = parent.frame(), quoted = FALSE) {
    if (!quoted) expr = substitute(expr)  # force quoted
    htmlwidgets::shinyRenderWidget(expr, eChartOutput, env, quoted = TRUE)
}
madlogos/recharts2 documentation built on May 21, 2019, 11:03 a.m.