Streamlit and pygwalker

Hi,

I ask myself if it would be feasible to implement the pygwalker library inside streamlit.
The only documentation I have found is the following:

Streamlit (Since version 0.1.4.9), enabled with pyg.walk(df, env=‘Streamlit’)

for jupyter and the voila component is quite simple and well documented.

import pandas as pd
import pygwalker as pyg

df = pd.read_excel(…/Destrucciones.xlsx’, sheet_name=‘Destruccion’)
gwalker = pyg.walk(df)

I have also implemented pivotable.js to streamlit adding different storage files.
but I also find this library easy and operational “pygwalker” to implement for people who do not have programming skills.

1 Like

Hey @Oscar1,

Thanks for sharing this with the community!

I hadn’t heard of pygwalker before – it looks pretty cool. As you mentioned, it looks like pygwalker does support usage in a Streamlit app.

Do you have a specific question you’re looking for input on?

Hi Caroline.

I try to run this library on streamlit but I have doubts that it can be supported by streamlit,I get the following error: <IPython.core.display.HTML object>.

using the following code:

import pandas as pd
import pygwalker as pyg
import streamlit as st


st.set_page_config(layout="wide")


st.title("Data Analysis with PyGWalker.")

df = None


with st.sidebar:
    uploaded_files = st.file_uploader("Choose a CSV file")
    if uploaded_files is not None:
        df = pd.read_csv(uploaded_files)


if df is not None:
    df = df.reset_index()
    html_output = pyg.walk(df, env='Streamlit')
    st.write(html_output, unsafe_allow_html=True)
    #st.markdown(html_output, unsafe_allow_html=True)
else:
    st.write("No se ha cargado ningún archivo CSV.")
1 Like

Hi,

pygwalker now provides official guidance to build with streamlit. Check the docs here:

Exploring Data and Sharing Findings with Pygwalker and Streamlit

Hi,

Thank you very much for your help

Hello,

I’m working on a PygWalker project and using a Streamlit. I’ve come across this warning:

WARNING: parse invoke code failed, This may affect feature of export code.

Could you please advise on suppressing this warning? Your guidance on this specific context would be greatly appreciated.

Thank you for your time.

Best regards,
Dilip

Hello,

One possibility is that the invocation code is incorrect or not compatible with pygwalker. Another possibility is that you are using a version of pygwalker that is not compatible with your version of streamlit.

Best regards,
Óscar

Hi Oscar1,

thanks for the reply. Please find the code and the versions below.

import streamlit as st
st.version
‘1.26.0’
import pygwalker as pyg
pyg.version
‘0.3.5’

  import numpy as np
  import pandas as pd
  import streamlit.components.v1 as stc 
  import warnings
  warnings.filterwarnings("ignore", category=UserWarning, message="parse invoke code failed")
  import pygwalker as pyg 
  
  def PYG_WALKER(TEXT_DATA, CAT_DATA ,START_D, END_D, Y_DATA):
      
      DATA = pd.DataFrame()
      
      if len(TEXT_DATA) !=0:
          TC = TEXT_DATA.columns
          
          DATA[TC] = TEXT_DATA
      
      if len(CAT_DATA) !=0:
          CAT_col = list(CAT_DATA.columns)
          DATA[CAT_col] = CAT_DATA[CAT_col]
          
      if len(START_D) !=0:
          START_D_col = START_D.name
          DATA[START_D_col] = START_D
          
      if len(END_D) !=0:
          END_D_col = END_D.name
          DATA[END_D_col] = END_D
          
      if len(Y_DATA) !=0:
          Y_col = list(Y_DATA.columns)[0]
          DATA[Y_col] = Y_DATA[Y_col]
          
      for col in DATA.columns:
          try:
              DATA[col] = DATA[col].replace("NO-VALUE", np.nan)
              try:
                  DATA[col] = DATA[col].replace("", np.nan)
              except:
                  pass
          except:
              pass    
    
      pyg_html = pyg.walk(DATA,env='Streamlit', return_html=True)
      
      stc.html(pyg_html,scrolling=True,height=920)

I no idea why iam getting the warning, if you can assist on this i will be grateful.

thanks,
Dilip.

Hi

I would remove the warnings import and the warnings.filterwarnings() line. These lines are used to suppress a warning that is raised by the pygwalker library.

You can test this correction:

import numpy as np
import pandas as pd
import streamlit.components.v1 as stc
import pygwalker as pyg
import streamlit as st

st.set_page_config(layout=“wide”,
page_title=“Prueba”,
page_icon=“‍🗞”)

def PYG_WALKER(TEXT_DATA, CAT_DATA, START_D, END_D, Y_DATA):

DATA = pd.DataFrame()

if len(TEXT_DATA) != 0:
    TC = TEXT_DATA.columns
    DATA[TC] = TEXT_DATA

if len(CAT_DATA) != 0:
    CAT_col = list(CAT_DATA.columns)
    DATA[CAT_col] = CAT_DATA[CAT_col]

if len(START_D) != 0:
    START_D_col = START_D.name
    DATA[START_D_col] = START_D

if len(END_D) != 0:
    END_D_col = END_D.name
    DATA[END_D_col] = END_D

if len(Y_DATA) != 0:
    Y_DATA = pd.DataFrame(Y_DATA)
    Y_col = list(Y_DATA.columns)[0]
    DATA[Y_col] = Y_DATA[Y_col]

for col in DATA.columns:
    try:
        DATA[col] = DATA[col].replace("NO-VALUE", np.nan)
        try:
            DATA[col] = DATA[col].replace("", np.nan)
        except:
            pass
    except:
        pass

pyg_html = pyg.walk(DATA, env='streamlit', return_html=True)

stc.html(pyg_html, scrolling=True, height=920)

Creamos los datos

TEXT_DATA = pd.DataFrame({
“text”: [“Este es un texto”, “Este es otro texto”, “Este es un texto más largo”]
})
CAT_DATA = pd.DataFrame({
“categoría”: [“categoría 1”, “categoría 2”, “categoría 3”]
})
START_D = pd.Series([“2023-07-20”, “2023-07-21”, “2023-07-22”])
END_D = pd.Series([“2023-07-21”, “2023-07-22”, “2023-07-23”])
Y_DATA = pd.Series([1, 2, 3])

Ejecutamos la función

PYG_WALKER(TEXT_DATA, CAT_DATA, START_D, END_D, Y_DATA)