|
| 1 | +import altair as alt |
| 2 | +import pandas as pd |
| 3 | +from chartlets import Component, Input, State, Output |
| 4 | +from chartlets.components import Tabs, Tab, Typography, Box, VegaChart |
| 5 | + |
| 6 | +from server.context import Context |
| 7 | +from server.panel import Panel |
| 8 | + |
| 9 | + |
| 10 | +panel = Panel(__name__, title="Panel H") |
| 11 | + |
| 12 | + |
| 13 | +@panel.layout(State("@app", "selectedDatasetId")) |
| 14 | +def render_panel( |
| 15 | + ctx: Context, |
| 16 | + selected_dataset_id: str = "", |
| 17 | +) -> Component: |
| 18 | + dataset = ctx.datasets.get(selected_dataset_id) |
| 19 | + |
| 20 | + c = ( |
| 21 | + alt.Chart(dataset) |
| 22 | + .mark_bar() |
| 23 | + .encode( |
| 24 | + x=alt.X("x:N", title="x"), |
| 25 | + y=alt.Y("a:Q", title="a")) |
| 26 | + ) |
| 27 | + |
| 28 | + chart = VegaChart( |
| 29 | + id="chart1", chart=c, style={"flexGrow": 1} |
| 30 | + ) |
| 31 | + |
| 32 | + info_text = Typography(id="info_text", children=["hallo"]) |
| 33 | + |
| 34 | + tab1=Tab(id = "tab1",label="Plot 1", children=["Hallo"]) |
| 35 | + tab2=Tab(id = "tab2",label="Plot 2", children=[info_text]) |
| 36 | + tab3 = Tab(id="tab3", label="Plot 3", children=[chart]) |
| 37 | + |
| 38 | + select = Tabs(id = "tab", value = 0, children=[tab1,tab2,tab3]) |
| 39 | + |
| 40 | + |
| 41 | + return Box( |
| 42 | + style={ |
| 43 | + "display": "flex", |
| 44 | + "flexDirection": "column", |
| 45 | + "width": "100%", |
| 46 | + "height": "100%", |
| 47 | + }, |
| 48 | + children=[chart, info_text, select,tab2], |
| 49 | + ) |
| 50 | + |
0 commit comments