Closed Louis-udm closed 1 year ago
If you want to use to_html
, try:
walker = pyg.walk(all_df, spec=vis_spec)
walker.to_html()
I will add this to the tutorial today. Here is an example demo app shows how the API works https://github.com/ObservedObserver/pygwalker-dash/blob/main/app.py
pyg.to_html
is deprecated function.
refer answer of ObservedObserver.
Thanks @ObservedObserver and @longxiaofei !
I actually used streamlit
and referred to this blog: https://docs.kanaries.net/pygwalker/use-pygwalker-with-streamlit#saving-pygwalker-chart-state
Then I changed the code to:
walker = pyg.walk(all_df, spec=vis_spec)
pyg_html = walker.to_html()
When I run it again, I see a endless loop that prints endless chars on the terminal. Then I also tried change to us dash like in https://github.com/ObservedObserver/pygwalker-dash/blob/main/app.py, and the endless loop appeared again.
@Louis-udm Hi, you can use new pygwalker in streamlit.
refer: https://github.com/Kanaries/pygwalker/releases/tag/0.3.8.
I haven't updated the new document yet.
I am using pygwalker 0.3.9 under python 3.10, should I downgrade to 0.3.8? I found by using this code, the endless print loop appears.
walker = pyg.walk(all_df)
pyg_html = walker.to_html()
It should not be a cycle, just a long string. This bug will be fixed in the next version.
If you use streamlit.
try it.
from pygwalker.api.streamlit import StreamlitRenderer, init_streamlit_comm
import pandas as pd
import streamlit as st
# Adjust the width of the Streamlit page
st.set_page_config(
page_title="Use Pygwalker In Streamlit",
layout="wide"
)
# Initialize pygwalker communication
init_streamlit_comm()
@st.cache_resource
def get_pyg_renderer() -> "StreamlitRenderer":
df = pd.DataFrame()
# When you need to publish your application, you need set `debug=False`,prevent other users to write your config file.
return StreamlitRenderer(df, spec="./gw_config.json", debug=True)
renderer = get_pyg_renderer()
renderer.render_explore()
This is the best practice in streamlit.
It should not be a cycle, just a long string. This bug will be fixed in the next version.
If you use streamlit.
try it.
from pygwalker.api.streamlit import StreamlitRenderer, init_streamlit_comm import pandas as pd import streamlit as st # Adjust the width of the Streamlit page st.set_page_config( page_title="Use Pygwalker In Streamlit", layout="wide" ) # Initialize pygwalker communication init_streamlit_comm() @st.cache_resource def get_pyg_renderer() -> "StreamlitRenderer": df = pd.DataFrame() # When you need to publish your application, you need set `debug=False`,prevent other users to write your config file. return StreamlitRenderer(df, spec="./gw_config.json", debug=True) renderer = get_pyg_renderer() renderer.render_explore()
This is the best practice in streamlit.
It works!
@Louis-udm
or, you want to only get html, try it:
walker = pyg.walk(df, env="others")
pyg_html = walker.to_html()
Because Pygwalker was developed as a jupyter tool before, so many functions are coupled with Jupyter.
When using pygwalker on other platforms, these methods can be confusing.
We will improve it.
Hi,
I got an error when do pyg_html = pyg.to_html(all_df, spec=vis_spec) and the vis_spec is copied from PygWalker UI. I tryied
copy python string
orexport as json file
, and does not work for both.