R/plotly.R

Defines functions plotly_server plotly_ui

Documented in plotly_server plotly_ui

#' The plotly UI for bs4dash
#'
#' The plotly functions create a server-side interaction to be handled
#' by data and parameters set in the server
#'
#' @param id is unique ID associated with the plotly for the UI namespace
#'
#' @importFrom shiny uiOutput
#'
#' @export

plotly_ui <- function(id) {
  ns <- NS(id)
  uiOutput(ns("plotly"))
}

#' The plotly server for bs4dash
#'
#' The plotly functions create a server-side interaction to be handled
#' by conditional logic for the parameters (\code{reactive})
#'
#'
#' @param input list of inputs used in the shiny application session
#' @param output list of outputs used the shiny application session
#' @param session The shiny app session object
#' @param plotly_fn the plotly function call
#' @param width The width of the plotly output for the UI
#'
#' @importFrom plotly plotlyOutput
#' @importFrom plotly renderPlotly
#'
#' @export

plotly_server <-
  function(input, output, session, plotly_fn, width = "100%") {
    ns <- session$ns

    #Declare the server-side visualization
    output[['plotly']] <- renderUI({
      plotlyOutput(ns("viz"), width = width)
    })

    #Include the plotly visual to display
    output[['viz']] <- renderPlotly({
      plotly_fn()
    })
  }
HarryRosen/hrimodules documentation built on Jan. 11, 2022, 12:36 a.m.