# PyGWalker starting point: a drag-and-drop explorer over a filtered dataframe.
# Template: ~35 lines, adapt by swapping `tips` for your own dataframe and the filter for yours.
# Run: uv run --no-sync shiny run website/widgets/pygwalker/gallery/template_explorer.py
# Data: plotly.express.data.tips() (ships with plotly)
import plotly.express as px
import pygwalker
from shiny.express import input, ui

from shinywidgets import render_pygwalker

# Optional: stop PyGWalker's update checks (server and browser)
pygwalker.GlobalVarManager.set_privacy("offline")

ui.page_opts(title="Tips explorer", fillable=True)

tips = px.data.tips()

with ui.sidebar():
    ui.input_select(
        "day", "Day", choices=["All", *sorted(tips["day"].unique())], selected="All"
    )
    ui.input_select(
        "time", "Time", choices=["All", *sorted(tips["time"].unique())], selected="All"
    )

with ui.card(full_screen=True):

    @render_pygwalker
    def explorer():
        df = tips
        if input.day() != "All":
            df = df[df["day"] == input.day()]
        if input.time() != "All":
            df = df[df["time"] == input.time()]
        return df
