|
| 1 | +import altair as alt |
| 2 | + |
| 3 | +from chartlets import Component, Input, State, Output |
| 4 | +from chartlets.components import (Tabs, Tab, Typography, Box, |
| 5 | + VegaChart, Table) |
| 6 | +from chartlets.components.table import TableColumn, TableRow |
| 7 | + |
| 8 | +from server.context import Context |
| 9 | +from server.panel import Panel |
| 10 | + |
| 11 | + |
| 12 | +panel = Panel(__name__, title="Panel H") |
| 13 | + |
| 14 | + |
| 15 | +@panel.layout(State("@app", "selectedDatasetId")) |
| 16 | +def render_panel( |
| 17 | + ctx: Context, |
| 18 | + selected_dataset_id: str = "", |
| 19 | +) -> Component: |
| 20 | + dataset = ctx.datasets.get(selected_dataset_id) |
| 21 | + |
| 22 | + columns: list[TableColumn] = [ |
| 23 | + {"id": "id", "label": "ID", "sortDirection": "desc"}, |
| 24 | + { |
| 25 | + "id": "firstName", |
| 26 | + "label": "First Name", |
| 27 | + "align": "left", |
| 28 | + "sortDirection": "desc", |
| 29 | + }, |
| 30 | + {"id": "lastName", "label": "Last Name", "align": "center"}, |
| 31 | + {"id": "age", "label": "Age"}, |
| 32 | + ] |
| 33 | + |
| 34 | + rows: TableRow = [ |
| 35 | + ["1", "John", "Doe", 30], |
| 36 | + ["2", "Jane", "Smith", 25], |
| 37 | + ["3", "Peter", "Jones", 40], |
| 38 | + ] |
| 39 | + |
| 40 | + table = Table(id="table", rows=rows, columns=columns, hover=True) |
| 41 | + |
| 42 | + info_text = Typography(id="info_text", children=["This is a text."]) |
| 43 | + chart = VegaChart( |
| 44 | + id="chart", chart=( |
| 45 | + alt.Chart(dataset) |
| 46 | + .mark_bar() |
| 47 | + .encode( |
| 48 | + x=alt.X("x:N", title="x"), |
| 49 | + y=alt.Y("a:Q", title="a")) |
| 50 | + .properties(width=290, height=300, title="Vega charts") |
| 51 | + ), style={"flexGrow": 1} |
| 52 | + ) |
| 53 | + |
| 54 | + tab1 = Tab(id = "tab1", label="Tab 1", children=[table]) |
| 55 | + tab2 = Tab(id = "tab2", label="Tab 2", children=[info_text]) |
| 56 | + tab3 = Tab(id="tab3", label="Tab 3", children=[chart]) |
| 57 | + |
| 58 | + tabs = Tabs(id = "tabs", value = 0, children=[tab1,tab2,tab3]) |
| 59 | + |
| 60 | + return Box( |
| 61 | + style={ |
| 62 | + "display": "flex", |
| 63 | + "flexDirection": "column", |
| 64 | + "width": "100%", |
| 65 | + "height": "100%", |
| 66 | + }, |
| 67 | + children=[ tabs ], |
| 68 | + ) |
| 69 | + |
0 commit comments