---
title: "Get Started"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Get Started}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup}
library(shinydataviewer)
library(shiny)
library(bslib)
```

`shinydataviewer` provides a reusable Shiny module for viewing data with:

- a `reactable` data viewer
- a variable summary sidebar
- Bootstrap 5 compatible styling via `bslib`

The module supports data frames with numeric, integer, character, factor,
logical, `Date`, and `POSIXct`/`POSIXt` columns. Non-finite numeric values such
as `Inf`, `-Inf`, and `NaN` are excluded from numeric summary statistics and
histogram bins.

## Interface preview

```{r, echo = FALSE, out.width = "100%", fig.cap = "The data viewer combines per-variable summary cards with a searchable table."}
knitr::include_graphics("figures/screenshot.png")
```

## Minimal module

Use `data_viewer_ui()` when the viewer should manage its own table card.

```{r eval = FALSE}
ui <- page_fillable(
  theme = bs_theme(version = 5),
  data_viewer_ui("viewer")
)

server <- function(input, output, session) {
  data_viewer_server(
    "viewer",
    data = reactive(iris)
  )
}

shinyApp(ui, server)
```

## Embedded card

Use `data_viewer_card_ui()` when the viewer belongs inside another layout.

```{r eval = FALSE}
ui <- page_fillable(
  theme = bs_theme(version = 5),
  layout_columns(
    col_widths = c(4, 8),
    card(
      card_header("Context"),
      card_body("Supporting content")
    ),
    data_viewer_card_ui(
      "viewer",
      title = "Dataset",
      full_screen = FALSE
    )
  )
)

server <- function(input, output, session) {
  data_viewer_server(
    "viewer",
    data = reactive(mtcars)
  )
}

shinyApp(ui, server)
```

## Summary helper

The variable sidebar is backed by `summarize_columns()`.

```{r}
summary_df <- summarize_columns(head(iris), top_n = 4)

summary_df[c("var_name", "type", "n_missing", "n_unique")]
```

`summarize_columns()` returns one row per input column. Its `summary_stats` and
`distribution_data` list-columns contain the precomputed payloads used by the
viewer cards, including detail statistics, categorical top-level counts, and
compact histogram metadata.

## Example app

A runnable embedded example is included at
`inst/examples/embedded-card-example.R`.
