Skip to main content

How to get started with Streamlit apps.

  • July 23, 2025
  • 0 replies
  • 49 views

Ben Petree
Seasoned Practitioner
Forum|alt.badge.img+4

How to get started with Streamlit apps.

 

You can easily build Python apps with Streamlit from the Cognite Data Fusion (CDF) user interface. Navigate to fusion.cognite.com and log in to your CDF project. We don’t have a sandbox or demo project set up for testing Streamlit as of now, so you will need access to a CDF project through your company. Try the Streamlit playground if you want to try out Streamlit components without your data.

 

Under the Data management workspace, and the Build solutions drop-down, you find Streamlit apps.

AD_4nXeva7vENfICHUieTuZsrbPvHWrT60FGVtiF9f55OoDWRVsMJ_DnO789BrbvxOINu4z-d2lb0CmsrF_f-ZH9UwtXxAYvepz4dNtJE1q3J8tBS4uvMMkrHdM8xyofJnF1R587rv3z?key=9X3V6pHmmopejyCLk3cVrA

Here you can view all Streamlit apps that you have access to. Let's create our own. Click the blue Create app button. Give your new app a great name, something that other users will easily recognize when they come to use your app. We want to make an app that can visualize our time series data.

 

AD_4nXdu9ouVaXZJo67IrsPPEoh3BRR2pgcECiVMqOX1e5SDfP6xrwixGKfwyfhNgZZPJcAzUiGpnzLTRc15lKeBrq0ael32NsquizHmSdmr_8XPjCNNQuoXn65KvADpNO7DRx5mRN6jkA?key=9X3V6pHmmopejyCLk3cVrA

 

Once we click OK. We can fill in the Python code needed for our app. For this example, we used the following code: 

import plotly.graph_objs as go

import streamlit as st



from cognite.client import CogniteClient

from cognite.client.data_classes.data_modeling import ViewId

from cognite.client.data_classes.data_modeling.query import Query



# Create client with user's auth

client = CogniteClient()



# Where the data is

schema_space = "IceCreamFactorySchema"

view = "IceCreamFactoryTimeSeries"



# Get 25 unordered nodes

time_series = client.data_modeling.instances.list(

   instance_type="node",

   sources=ViewId(schema_space, view, "v1"),

)



# make the selection box readable

selection = st.selectbox(

   "Which Time series do you wanna see?",

   time_series,

   format_func=lambda x:x.external_id

)



# All the datapoints for the selected time series

datapoints = client.time_series.data.retrieve_dataframe(

   instance_id=selection.as_id()

)



# Plotly supports stepwise line graphs

fig = go.Figure(

   data=go.Scatter(

       x=datapoints.index,

       y=datapoints[datapoints.columns[0]],

       mode="lines",

       line={"shape": "hv"}

   ),

   layout={

       "title": selection.external_id,

       "xaxis_title": "Timestamp",

   }

)



st.plotly_chart(fig)

 

We are given the following warning every time we open any Streamlit app. Please make sure to check with the CDF Admin or the author of the app before running it if you are unsure that the app is suitable. 

 

AD_4nXe6-8LHAGBIe1O0m9QkxgsQsZG0LsOcgYOvtqmsqOudkj7f5cNHWbpWJEsSn5o5uv_pUM-cCK4mmcyyFED90LIPld5U4kNNxRiWtQs7lxlsBKUWxo2S7WDUFB2F4lYb7G6QALb6xQ?key=9X3V6pHmmopejyCLk3cVrA

 

The data model we are using for this app looks like this:

 

AD_4nXcpkM5hI98G57YTcgQ-dr0sOdFR0NvKxUOyohwKO3f3doLP0qpSz5P2VAYwrnxKQT8T0s9Qj_6rjH_D8YPpFuRvubiQ8Zbu2G6A-pU_rDfa0GDiGa25LbyuNPjUvjYX-y7oGI9scA?key=9X3V6pHmmopejyCLk3cVrA

 

After running the script, we have our app that visualizes our selected time series from a drop-down menu. 

 

AD_4nXeAyOB1uslO7ABOPkbB0ID3ah3F4fy4wmZs1Gbss8bdnG9sd0Z7YoKMbaS0VbgyPofDNjIHr7KjCmx7t24q8UUZ9FMr84WB4At4Uixw-rJ2013ucjzq4CBIupwym-dmKg3fB7uOwA?key=9X3V6pHmmopejyCLk3cVrA

 

Here are some helpful links to the documentation used to build this guide.

 

List all data modeling instances:

https://cognite-sdk-python.readthedocs-hosted.com/en/latest/data_modeling.html#list-instances

 

Selection box: https://docs.streamlit.io/develop/api-reference/widgets/st.selectbox

 

Retrieve all datapoints for selected Time series: https://cognite-sdk-python.readthedocs-hosted.com/en/latest/time_series.html#retrieve-datapoints-in-pandas-dataframe

 

Line graph: https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html

 

Draw the line graph: https://docs.streamlit.io/develop/api-reference/charts/st.plotly_chart