Generate a sample demo view Returns: A datapane View object for saving or uploading
()
| 91 | |
| 92 | |
| 93 | def demo() -> Blocks: |
| 94 | """ |
| 95 | Generate a sample demo view |
| 96 | |
| 97 | Returns: |
| 98 | A datapane View object for saving or uploading |
| 99 | """ |
| 100 | |
| 101 | import altair as alt # noqa |
| 102 | import folium # noqa |
| 103 | import matplotlib.pyplot as plt # noqa |
| 104 | import plotly.graph_objects as go # noqa |
| 105 | from bokeh.plotting import figure # noqa |
| 106 | |
| 107 | def _gen_bokeh(**kw): |
| 108 | p = figure(title="simple line example", x_axis_label="x", y_axis_label="y", **kw) |
| 109 | p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], legend_label="Temp.", line_width=2) |
| 110 | return p |
| 111 | |
| 112 | def _gen_plotly(): |
| 113 | fig = go.Figure() |
| 114 | fig.add_trace(go.Scatter(x=[0, 1, 2, 3, 4, 5], y=[1.5, 1, 1.3, 0.7, 0.8, 0.9])) |
| 115 | fig.add_trace(go.Bar(x=[0, 1, 2, 3, 4, 5], y=[1, 0.5, 0.7, -1.2, 0.3, 0.4])) |
| 116 | return fig |
| 117 | |
| 118 | def _gen_matplotlib(): |
| 119 | # pd.set_option("plotting.backend", "matplotlib") |
| 120 | fig, ax = plt.subplots() |
| 121 | df = gen_df() |
| 122 | ax.plot(df["x"], df["y"]) |
| 123 | # gen_df().plot.scatter("x", "y", ax=ax) |
| 124 | return fig |
| 125 | |
| 126 | def _gen_html(w: int = 30, h: int = 30): |
| 127 | return b.HTML( |
| 128 | f""" |
| 129 | <div style="width: {w}rem; height: {h}rem; background-color: rgba(0, 0, 255, 0.2); position: relative"> |
| 130 | <div style="position: absolute; right: 50%; bottom: 50%; transform: translate(50%, 50%);"> |
| 131 | HTML Block |
| 132 | </div> |
| 133 | </div>""" |
| 134 | ) |
| 135 | |
| 136 | def _color_large_vals(s: t.Any): |
| 137 | return ["background-color: rgba(255, 0, 0, 0.3)" if val > 800 else "" for val in s] |
| 138 | |
| 139 | def _gen_folium(): |
| 140 | return folium.Map(location=[45.372, -121.6972], zoom_start=12, tiles="Stamen Terrain") |
| 141 | |
| 142 | df1 = gen_table_df(10) |
| 143 | styler1 = df1.style.apply(_color_large_vals, axis=1).hide(axis="index") |
| 144 | |
| 145 | def _vega_sine(): |
| 146 | x = np.arange(100) |
| 147 | source = pd.DataFrame({"x": x, "f(x)": np.sin(x / 5)}) |
| 148 | |
| 149 | return alt.Chart(source).mark_line().encode(x="x", y="f(x)") |
| 150 |
nothing calls this directly
no test coverage detected