import streamlit as st
import pandas as pd
import dtale
import pygwalker as pygwalk
import threading
# Function to read the Titanic dataset
def read_titanic_data():
# Assuming the CSV file is named 'titanic.csv' and located in the same directory as your Python script
# If the file is located in a different directory, provide the full path to the file
titanic_df = pd.read_csv('titanic.csv')
return titanic_df
# Function to display data using dtale
def display_with_dtale(data):
dtale_instance = dtale.show(data)
return dtale_instance
# Function to start pygwalk server in a separate thread
def start_pygwalk_server(data):
pygwalk.show(data)
def main():
st.title('Visualization Tools for Titanic Dataset')
# Read the Titanic dataset
data = read_titanic_data()
# Create radio buttons for visualization tools
visualization_tool = st.radio("Choose Visualization Tool", ["dtale", "pygwalk"], horizontal=True)
if visualization_tool == "dtale":
st.write("You selected dtale")
run_button = st.button("Run")
stop_button = st.button("Stop")
if run_button:
if 'dtale_instance' not in st.session_state:
st.session_state.dtale_instance= dtale.show(data)
else:
st.session_state.dtale_instance.kill()
st.session_state.dtale_instance= dtale.show(data)
dtale_url = st.session_state.dtale_instance.main_url()
st.components.v1.html(f'<iframe src="{dtale_url}" width="1000" height="600" style="border:none;"></iframe>', height=700)
if stop_button and st.session_state.dtale_instance:
st.session_state.dtale_instance.kill()
elif visualization_tool == "pygwalk":
st.write("You selected pygwalk")
run_button = st.button("Run")
stop_button = st.button("Stop")
pygwalk_instance = None
if run_button:
pygwalk_thread = threading.Thread(target=start_pygwalk_server, args=(data,))
pygwalk_thread.start()
st.write("Pygwalk server started. Please open the browser and navigate to the provided URL.")
if stop_button and pygwalk_instance:
# Currently, pygwalk doesn't provide a direct way to stop the server programmatically
# You would typically need to stop the server manually (e.g., Ctrl+C in the terminal)
st.write("To stop pygwalk, please manually stop the server")
if __name__ == "__main__":
main()
Hi, it seems the code uses some API of pygwalker that does not exist.
You can check this pygwalker example of how to use with streamlit: How to Use PyGWalker with Streamlit โ Nextra
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.