R/plot.R

Defines functions tippy_plot

Documented in tippy_plot

#' Use a plot as tooltip
#' 
#' @inheritParams tippyThis
#' @param plotId Id of plot to use.
#' @param .width,.height Dimensions of plot.
#' @param .hidePlot Whether to hide the original plot.
#' @param .session A valid shiny session.
#' 
#' @examples 
#' library(shiny)
#' 
#' ui <- fluidPage(
#'   useTippy(),
#'   plotOutput("plot"),
#'   h5("plot tooltip", id = "plotTip")
#' )
#' 
#' server <- function(input, output) {
#'   output$plot <- renderPlot({
#'     on.exit({
#'       tippy_plot(
#'         "plotTip", 
#'         "plot", 
#'         theme = "light",
#'         .hidePlot = TRUE,
#' 				 .width = 600,
#' 				 .height = 200,
#'         maxWidth = 700
#'       )
#'     })
#'     plot(cars)
#'   })
#' }
#' 
#' if(FALSE){
#'   shinyApp(ui, server)
#' }
#' 
#' @export 
tippy_plot <- function(
	selector,
	plotId,
	...,
	.width = 200,
	.height = 200,
	.hidePlot = FALSE,
	.session = shiny::getDefaultReactiveDomain()
) {
	cat("This is an experimental feature\n")
	.session$sendCustomMessage(
		"tippy-plot",
		list(
			hide = .hidePlot,
			plotOptions = list(
				height = .height,
				width = .width
			),
			selector = make_selector(selector),
			target = make_selector(plotId),
			options = list(...)	
		)
	)
}
JohnCoene/tippy documentation built on April 16, 2023, 2:37 p.m.