Kanaries / pygwalker

PyGWalker: Turn your pandas dataframe into an interactive UI for visual analysis
https://kanaries.net/pygwalker
Apache License 2.0
13.41k stars 699 forks source link

Possibility to save spec when spec param is not json file #619

Closed ymurong closed 2 months ago

ymurong commented 2 months ago

Currently, the walker instance does not have updated spec unless you click on the save button that inject the newest spec back to python backend (which does not work when spec param is not json_file).

I am providing pygwalker in streamlit as a standalone application for a group of people as an online tool. Instead of having a json file on server for each user, it is more practical to keep their spec in their session/localstorage. However, as the save does not work for spec in memory mode, the user has to export first their spec and then copy back so that I could regenerate a renderer with the new spec.

Is it technically feasible?

Thank you !

longxiaofei commented 2 months ago

Hi @ymurong

pygwalker already supports returning events when the spec changes in streamlit.

from pygwalker.api.streamlit import StreamlitRenderer
import pandas as pd
import streamlit as st

@st.cache_resource
def get_pyg_renderer() -> "StreamlitRenderer":
    df = pd.read_csv("xxx")
    return StreamlitRenderer(df)

renderer = get_pyg_renderer()

event = renderer.explorer()

print(event)

you can refer this issue: https://github.com/Kanaries/pygwalker/issues/580

ymurong commented 2 months ago

Hi @longxiaofei, Thank you for you rapid feedback. It works perfectly !