# Visualize EMQX Tables Data with Streamlit

[Streamlit](https://streamlit.io/) is an open-source framework for building interactive data apps in Python. With EMQX Tables’ compatibility with the MySQL protocol, you can easily integrate EMQX Tables into Streamlit applications for real-time data exploration and visualization.

## Connect Streamlit to EMQX Tables

To enable the connection, you must first install the `sqlalchemy` and `mysqlclient` libraries. Run the following command in your terminal:

```bash
pip install sqlalchemy mysqlclient
```

You can connect to EMQX Tables using any standard MySQL driver. Below is a basic example of setting up the connection and querying data using Streamlit’s experimental `st.connection()` method:

```python
import streamlit as st

# Establish SQL connection
st.title('EMQX Tables Streamlit Demo')
conn = st.connection("EMQX Tables", type="sql", url="mysql://{USER}:~~{PASSWORD}~~@{HOST}:4002/{DB_NAME}")

# Query data from EMQX Tables
df = conn.query("SELECT * FROM ...")

# Display results
st.dataframe(df)
```

> **Tip:** The result set is returned as a Pandas DataFrame, so you can directly visualize and interact with the data using Streamlit’s built-in charting features like `st.line_chart()`, `st.bar_chart()`, or custom plots with libraries like Plotly and Matplotlib.

## Notes

- Ensure your EMQX Tables deployment is publicly accessible if running Streamlit from your local environment.
- TLS is enabled by default on EMQX Tables. Make sure the MySQL driver in use supports secure connections.

## Learn More

- [Streamlit Documentation](https://docs.streamlit.io/)

  