% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/globals.R
\name{fire_event}
\alias{fire_event}
\alias{get_event}
\alias{get_theme}
\title{Fire or read a session event}
\usage{
fire_event(
  key,
  value,
  session = shiny::getDefaultReactiveDomain(),
  global = FALSE
)

get_event(key, session = shiny::getDefaultReactiveDomain(), default = NULL)

get_theme(session = shiny::getDefaultReactiveDomain())
}
\arguments{
\item{key}{a single character string identifying the event type}

\item{value}{the event payload (any R object)}

\item{session}{a Shiny session (defaults to the current reactive domain)}

\item{global}{logical; if \code{TRUE}, the event is broadcast to all
sessions sharing the same \code{shared_id}}

\item{default}{value to return when the event has not been fired yet
(used by \code{get_event} only)}
}
\value{
\code{fire_event} returns \code{NULL} invisibly.
  \code{get_event} returns the last value fired for \code{key}, or
  \code{default} if none.
  \code{get_theme} returns a named list with three character elements:
  \describe{
    \item{theme}{Either \code{"light"} or \code{"dark"}.}
    \item{foreground}{Hex color string for text / foreground elements.}
    \item{background}{Hex color string for the page background.}
  }
  Before the browser fires its first theme event, the light-theme fallback
  \code{list(theme = "light", background = "#FFFFFF", foreground = "#000000")}
  is returned.
}
\description{
\code{fire_event} sets a reactive event value on the current session.
When \code{global = TRUE}, the event is propagated to all sessions that
share the same \code{shared_id} (i.e. other browser tabs for the same
user).

\code{get_event} reads the current value of an event key from the
session registry.

\code{get_theme} is a convenience wrapper around
\code{get_event("theme.changed")} that returns the current dashboard theme.

All three functions must be called inside a Shiny server context.
}
\details{
\code{get_theme} and \code{get_event} auto-register the session if needed
and must be called inside a reactive context
(\code{\link[shiny]{observe}}, \code{\link[shiny]{observeEvent}},
\code{\link[shiny]{reactive}}, render functions).
}
\examples{


library(shiny)
server <- function(input, output, session) {
  # fire an event
  shidashi::fire_event("my_event", list(a = 1), session = session)

  # read it back
  observe({
    evt <- shidashi::get_event("my_event", session = session)
    print(evt)
  })

  # get_theme must be called within a reactive context
  output$plot <- renderPlot({
    theme <- shidashi::get_theme()
    par(bg = theme$background, fg = theme$foreground)
    plot(1:10)
  })
}


}
