Skip to content

About PyGWalker 0.3.8

Douding edited this page Oct 27, 2023 · 1 revision

About PyGWalker 0.3.8

Streamlit Multiple Rendering Modes

In pygwalker==0.3.7, we added a new communication feature in streamlit, which can help us implement many new feature in streamlit.

In pygwalker==0.3.8, pygwalker provide two rendering modes in streamlit,include explore and renderer mode.

explore mode helps developers explore datas and develop the charts they need to display.

renderer mode can only render the chart without displaying other tool buttons.

example url: https://pygwalker-in-app-vipsfjjsyx2p6wwmm8yey9.streamlit.app/

example code:

from pygwalker.api.streamlit import init_streamlit_comm, StreamlitRenderer

# Initialize pygwalker communication
init_streamlit_comm()


# You should cache your pygwalker renderer, if you don't want your memory to explode
@st.cache_resource
def get_pyg_renderer() -> "StreamlitRenderer":
    df = get_data()
    # When you need to publish your application, you need set `debug=False`,prevent other users to write your config file.
    return StreamlitRenderer(df, spec="./billion_config.json", debug=True)

renderer = get_pyg_renderer()

# Display explore ui, Developers can use this to prepare the charts you need to display.
renderer.render_explore()

# Display pure chart, index is the order of charts in explore mode, starting from 0.
renderer.render_pure_chart(0)

add pre-filters param in streamlit renderer.

We can pre-filter the data in the renderer and use it with other components of streamlit.

example url: https://pygwalker-in-app-vipsfjjsyx2p6wwmm8yey9.streamlit.app/

example code:

...

from pygwalker.api.streamlit import PreFilter

pre_filters = []
pre_filters.append(PreFilter(
    field="country",
    op="one of",
    value=["CN", "US", "EN"]
))

# set global pre-filters in renderer
renderer.set_global_pre_filters(pre_filters)

# Set a pre-filter for a certain chart, it will overwrite global pre-filters
renderer.render_pure_chart(0, pre_filters=pre_filters)

...