How do I visualize data from Snowflake in Streamlit?
To visualize data from Snowflake in Streamlit, you can use the following steps:
- Follow the steps above to access the data from Snowflake in Streamlit.
- Use the Streamlit visualization tools to create a graph, chart, or other visualization of the data.
Here are some examples of how to visualize data from Snowflake in Streamlit:
- To create a bar chart, you can use theÂ
st.bar_chart()
 function. - To create a line chart, you can use theÂ
st.line_chart()
 function. - To create a pie chart, you can use theÂ
st.pie_chart()
 function. - To create a scatter plot, you can use theÂ
st.scatter_plot()
 function.
You can also use the Streamlit st.plotly_chart()
function to create a more complex visualization using Plotly.
Here is an example of how to create a bar chart of the number of employees in each department from a Snowflake table:
import snowflake.connector as sf
import streamlit as st
# Get the user credentials from the secrets file
with open(".streamlit/secrets.toml") as f:
secret_data = f.read()
credentials = toml.load(secret_data)
# Connect to Snowflake
conn = sf.connect(
user=credentials["user"],
password=credentials["password"],
account=credentials["account"],
db=credentials["database"],
)
# Run a query
df = conn.execute("SELECT department, COUNT(*) AS num_employees FROM employees GROUP BY department")
# Create a bar chart
st.bar_chart(df, x="department", y="num_employees")