R/getBoxplotForEmptyData.R

Defines functions getBoxplotForEmptyData

Documented in getBoxplotForEmptyData

#' Utility Plotly function to return blank plot when useful
#'
#' @param text string defaults to "" - optional text to display in plot
#' @return returns empty Plotly scatter plot
#' @import dplyr
#' @import plotly
#' @export

getBoxplotForEmptyData <- function(text = "") {

  data <- tibble::as_tibble(list(x = 1, text = text))

  xaxis <- list(
    title = "",
    showgrid = FALSE,
    zeroline = FALSE,
    showline = FALSE,
    showticklabels = FALSE,
    fixedrange = TRUE
  )

  yaxis <- list(
    title = "",
    showgrid = FALSE,
    zeroline = FALSE,
    showline = FALSE,
    showticklabels = FALSE,
    fixedrange = TRUE
  )

  margin <- list(
    autoexpand = TRUE,
    l = 25,
    r = 15,
    t = 20,
    b = 20
  )

  plotly::plot_ly(
    data = data,
    x = ~x,
    y = ~x,
    text = ~ text,
    hoverinfo = "none",
    type = "scatter",
    mode = "none",
    colors = "white",
    marker = list(
      color = "white"
    )
  ) |>
    plotly::layout(
      title = "",
      xaxis = xaxis,
      yaxis = yaxis,
      margin = margin,
      showlegend = FALSE,
      annotations = list(
        x = 1,
        y = 1,
        text = ~text,
        xref = "x",
        yref = "y",
        showarrow = FALSE,
        arrowhead = 7,
        ax = 0,
        ay = 0,
        font = list(
          color = "#264E86",
          family = "sans serif",
          size = 32
        )
      )
    ) |>
    plotly::config(
      displayModeBar = FALSE,
      displaylogo = FALSE
    )
}
cusom/CUSOM.ShinyHelpers documentation built on Oct. 23, 2023, 6:50 a.m.