% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/crowd_output.R
\name{crowd_output}
\alias{crowd_output}
\title{Universal Output Function for Crowd Plots and Tables}
\usage{
crowd_output(
  plot_list,
  path = "crowd_output.docx",
  force_format = c("auto", "html", "docx"),
  ...
)
}
\arguments{
\item{plot_list}{Either:
\itemize{
\item A named list of ggplot2 objects (for HTML plots)
\item A named list of mschart objects (for DOCX plots)
\item A \code{saros_officer_plots} object (from \code{\link[=crowd_plots_as_officer]{crowd_plots_as_officer()}})
\item A data.frame or list of data.frames (for tables)
}}

\item{path}{Character. File path for DOCX output (e.g., \code{"output.docx"}).
Only used when not in a knitr/Quarto rendering context.
Default: \code{"crowd_output.docx"}.}

\item{force_format}{Character. Force a specific output format:
\itemize{
\item \code{"auto"} (default): Auto-detect based on context
\item \code{"html"}: Force HTML tabset output via \code{\link[=crowd_plots_as_tabset]{crowd_plots_as_tabset()}}
\item \code{"docx"}: Force DOCX file output via \code{\link[=crowd_plots_as_docx]{crowd_plots_as_docx()}}
}}

\item{...}{Additional arguments passed to \code{\link[=crowd_plots_as_tabset]{crowd_plots_as_tabset()}} or
\code{\link[=crowd_plots_as_docx]{crowd_plots_as_docx()}} depending on the detected/forced format.}
}
\value{
\itemize{
\item In knitr/Quarto context: Invisibly returns \code{NULL} (side effect: prints tabset markdown)
\item Outside knitr context: Invisibly returns the DOCX file path
}
}
\description{
Automatically detects the appropriate output method based on the rendering
context and input type. Simplifies workflows by providing a single function
that works for both Quarto/knitr rendering (HTML tabsets/tables) and officer-based
DOCX generation.
}
\details{
\strong{Context Detection:}
The function uses \code{getOption("knitr.in.progress")} to detect if code is
running within a knitr/Quarto rendering context:
\itemize{
\item \strong{In knitr/Quarto} → Generates HTML tabset via \code{\link[=crowd_plots_as_tabset]{crowd_plots_as_tabset()}}
\item \strong{Outside knitr} → Writes DOCX file via \code{\link[=crowd_plots_as_docx]{crowd_plots_as_docx()}}
}

This allows the same code to work in multiple contexts:
\itemize{
\item Quarto → HTML rendering
\item Quarto → DOCX rendering (still uses HTML output in document)
\item R script → Officer-based DOCX generation
}

\strong{Input Type Detection:}
The function automatically detects and handles different input types:
\itemize{
\item ggplot2 objects → Uses \code{\link[=crowd_plots_as_tabset]{crowd_plots_as_tabset()}} or \code{\link[=crowd_plots_as_docx]{crowd_plots_as_docx()}}
\item mschart objects → Uses \code{\link[=crowd_plots_as_docx]{crowd_plots_as_docx()}}
\item \code{saros_officer_plots} → Uses \code{\link[=crowd_plots_as_docx]{crowd_plots_as_docx()}}
\item data.frame/tables → Uses \code{\link[=crowd_tables_as_tabset]{crowd_tables_as_tabset()}} or writes to DOCX
}

\strong{Typical Workflow:}

\if{html}{\out{<div class="sourceCode r">}}\preformatted{# In a Quarto document - works for both HTML and DOCX output formats
plots <- makeme(
  data = ex_survey,
  dep = b_1:b_3,
  crowd = c("target", "others"),
  mesos_var = "f_uni",
  mesos_group = "Uni of A",
  type = if (is_rendering()) "cat_plot_html" else "cat_plot_docx"
)
crowd_output(plots)  # Auto-detects context and renders appropriately
}\if{html}{\out{</div>}}
}
\examples{
\dontrun{
# Example 1: In a Quarto document (auto-detects HTML context)
plots <- makeme(
  data = ex_survey,
  dep = b_1:b_3,
  crowd = c("target", "others"),
  mesos_var = "f_uni",
  mesos_group = "Uni of A",
  type = if (is_rendering()) "cat_plot_html" else "cat_plot_docx"
)
crowd_output(plots)

# Example 2: In an R script (auto-detects non-knitr context, writes DOCX)
plots <- makeme(
  data = ex_survey,
  dep = b_1:b_3,
  crowd = c("target", "others"),
  mesos_var = "f_uni",
  mesos_group = "Uni of A",
  type = "cat_plot_docx"
)
crowd_output(plots, path = "my_report.docx")

# Example 3: Force specific format
crowd_output(plots, force_format = "docx", path = "forced_output.docx")
}
}
\seealso{
\itemize{
\item \code{\link[=crowd_plots_as_tabset]{crowd_plots_as_tabset()}} for HTML tabset generation
\item \code{\link[=crowd_plots_as_docx]{crowd_plots_as_docx()}} for DOCX file creation
\item \code{\link[=is_rendering]{is_rendering()}} for context detection helper
\item \code{\link[=makeme]{makeme()}} for creating plots with crowd parameter
}
}
