Skip to content

docs: add streamlit integration example #73

Closed

Description

@jvdd

Minimal example;

import threading
import numpy as np
import polars as pl
import uvicorn
import streamlit as st
from flexviz import Figure, app, register_source
from flexviz.spec import encode_spec
 
HOST, PORT = "127.0.0.1", 8000
 
@st.cache_resource  # runs once, not on every rerun
def start_flexviz():
    n = 10_000_000
    df = pl.DataFrame({"t": np.arange(n), "value": np.cumsum(np.random.randn(n))})
    register_source("logs", df)          # swap for pl.scan_parquet("logs.parquet") — stays lazy
    threading.Thread(
        target=uvicorn.run, args=(app,),
        kwargs={"host": HOST, "port": PORT, "log_level": "warning"},
        daemon=True,
    ).start()
 
start_flexviz()
 
fig = Figure().add_line(x="t", y="value")   # bound to the server-side "logs" source
url = f"http://{HOST}:{PORT}/view?spec={encode_spec(fig.to_spec(source='logs'))}"
st.iframe(url, height=600)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions