Generates an interactive pie chart showing the distribution of observations by region using Plotly. Each slice of the pie represents a region, with proportions based on the sum of a specified observation variable.

obs_region_pie(data, plot_dir = NULL)

Arguments

data

A list containing: - `data.req`: a data frame that includes a column `region`, a numeric column `value`, and an observation count column named `varname.den`. - `varname`: the base name of the variable of interest (e.g., "n"). - `nice_varname`: a human-readable version of the variable name (unused in this function).

plot_dir

Optional string. Directory path where the plot will be saved as an HTML file. If `NULL` (default), the plot is not saved.

Value

A Plotly pie chart object representing the proportion of observations per region. Optionally saves the chart to an HTML file if `plot_dir` is provided.

Details

The function: - Replaces missing region values with `"Unspecified"`. - Aggregates data by region to compute total observations, number of rows, mean and standard deviation of `value`. - Calculates the proportion of total observations for each region. - Assigns colors using a rainbow palette (unless `colors_map` already exists in the environment). - Builds an interactive pie chart with detailed hover text and labels.