Issue with Run At Startup when using Streamlit

I currently developing another app that uses streamlit to display data from a VL53L5CX 8x8 TOF sensor. When running in applab hooked up in PC mode (direct connect) Streamlit opens up in the default browser no issue. But if I set the app to "Run at Startup" and apply power it appears that the app starts but the Streamlit browser window never opens up. So on the off chance i had to manually connect I typed in the default web address for streamlit and the browser said address could not connect.

Next step was to try "Run at Startup" with the " UNO Q Pin Toggle" example set to "Run at Startup" and found the following:

  1. With applab open and run at startup selected browser window did not automatically open, but if I type the address into the browser it will open and connect no issue. Now if I close applab I still can connect, display and change the LEDS.
  2. Powering off and restarting the Q and waiting for it to finish booting it will still work.

But if I do the same with Streamlit I can not connect.

Any ideas on how to make it work?

For reference here is my current main. Tried it a couple different ways - with user loop, main() etc


import numpy as np
import pandas as pd
import plotly.graph_objects as go
import time

from arduino.app_utils import App, Bridge

import streamlit as st
import config as config
from geometry import (
    CoordinateMethod,
    compute_zone_angles,
    distances_to_points,
)
from planner import PotentialFieldPlanner

print("Hello world!")

# --- Initialize Steering Planner ---
# Configure height bounds based on TOF_BOARD mounting position (in meters)
sensor_height_m = config.TOF_BOARD.world_position[1]  # 0.105 m (105 mm)
planner = PotentialFieldPlanner(
    safe_distance_m=0.50,  # 50 cm
    min_height_m=-(sensor_height_m - 0.03),  # Cut off floor at ~7.5 cm height
    max_height_m=0.20,
    k_rep=0.01,
)

st.set_page_config(layout="wide")
st.title("🛰️ UNO Q – Real‑Time 3D Point Cloud Viewer")

# --- Layout ---
col_plot, col_table = st.columns([2, 1])
placeholder_plot = col_plot.empty()
placeholder_table = col_table.empty()

# --- Controls ---
auto_refresh = st.sidebar.checkbox("Auto‑refresh", value=True)
refresh_rate = st.sidebar.slider("Refresh rate (seconds)", 0.05, 1.0, 0.1)

def make_3d_plot(points, steering_cmd=None):
    x = points[:, 0] + config.TOF_BOARD.world_position[0]
    y = points[:, 1] + config.TOF_BOARD.world_position[1]
    z = points[:, 2] + config.TOF_BOARD.world_position[2]

    fig = go.Figure()

    # Point Cloud
    fig.add_trace(
        go.Scatter3d(
            x=z,
            y=x,
            z=y,
            mode="markers",
            marker=dict(size=3, color=x, colorscale="Viridis", opacity=0.8),
            name="ToF Cloud",
        )
    )

    # Optional: Plot Steering Vector Line
    if steering_cmd and steering_cmd.obstacle_detected:
        # Scale vector for visualization length
        vec_length = 0.3
        rad = np.radians(steering_cmd.steering_angle_deg)
        target_x = vec_length * np.sin(rad)
        target_z = vec_length * np.cos(rad)

        fig.add_trace(
            go.Scatter3d(
                x=[config.TOF_BOARD.world_position[2], target_z],
                y=[config.TOF_BOARD.world_position[0], target_x],
                z=[
                    config.TOF_BOARD.world_position[1],
                    config.TOF_BOARD.world_position[1],
                ],
                mode="lines+markers",
                line=dict(color="red", width=6),
                name="Steering Vector",
            )
        )

    fig.update_layout(
        height=700,
        scene=dict(
            xaxis_title="Z Forward (m)",
            yaxis_title="X Lateral (m)",
            zaxis_title="Y Height (m)",
            aspectmode="data",
        ),
    )
    return fig
    

def fetch_range():
    """
    Calls UNO Q get_range RPC.
    Expected format per line:
    A,<angle>,<range>,<quality>,<flag>
    """
    try:
        ranges = Bridge.call("get_range")

        # Ensure everything is a numpy array
        ranges = np.array(ranges, dtype=np.int32)

        return ranges

    except Exception as e:
        # print(f"Error fetching LIDAR data: {e}")
        return None
        
#def main():

t = 0
zone_angles = compute_zone_angles()

while(True):
    ranges = fetch_range()
    
    if ranges is not None:  
        if np.any(ranges > 0):
            points_local = distances_to_points(
                ranges,
                zone_angles,
                CoordinateMethod.ST_LOOKUP
            )

            # 2. Compute Steering Vector
            cmd = planner.compute_steering(points_local)

            # 3. Streamlit UI Indicators
            if cmd.obstacle_detected:
                st.warning(
                    f"🚨 Obstacle @ {cmd.min_distance_m*100:.0f} mm | Steer: {cmd.steering_angle_deg:.1f}°"
                )
            else:
                st.success("🟢 Clear Path Ahead")
       
            # 4. Render 3D Plot with Steering Line
            fig = make_3d_plot(points_local, cmd)
            placeholder_plot.plotly_chart(fig, width="stretch", key=t)
        
            # --- Z‑only table ---
            z_values = points_local[:, 2]
            
            # Reshape into 8x8 grid
            z_grid = z_values.reshape((8, 8))
            
            # Convert to DataFrame with labeled rows/cols
            df_z = pd.DataFrame(
                z_grid,
                columns=[f"C{c}" for c in range(8)],
                index=[f"R{r}" for r in range(8)]
            )

        # Display in Streamlit
        placeholder_table.dataframe(df_z, height=400)

        # --- Table ---
        #df = pd.DataFrame(points_local, columns=["X", "Y", "Z"])
        #placeholder_table.dataframe(df, height=700, key=t)

        if not auto_refresh:
            break

        time.sleep(refresh_rate)
        if t>1000000:
            t=0
        t=t+1

#if __name__ == "__main__":
#    main()


App.run()

Just tried a simplier app that any one can try:
Streamlit Test.zip (2.0 KB)

I believe it is failing for me as well.

It won't open the page at startup... But if I stop it and then Start it manually it then shows the page, where I can choose clear, logo. ...

Thanks for checking but now wondering if this should be in this forum or in the AppLab forum.

Good question?

My gut says here. Applab to me are more like for, the scrollbars aren’t working, cut and paste,…

But maybe just me.

Hi @Merlin513. It seems that when you start the App using Arduino App Lab, it uses ADB to set up port forwarding from the UNO Q to the host machine. If you run an adb forward --list command on the host machine after starting an App that uses the "WebUI - Streamlit" Brick via App Lab, you will see something like this:

$ ./adb forward --list
3646313294 tcp:8800 tcp:8800
3646313294 tcp:7000 tcp:7000

If you restart App Lab, you will only see this:

$ ./adb forward --list
3646313294 tcp:8800 tcp:8800

And if you close App Lab, the command returns nothing at all.

However, this port forwarding is not actually required. You can instead access the web page generated by the app via the host name of the UNO Q. For example, I named my board uno-q-4-gb, so I can access the page by loading the following URL in my web browser:

http://uno-q-4-gb:7000

This works even if you didn't start the App via Arduino App Lab:

  • When the App automatically starts due to being configured as the "Run at Startup" App.
  • When the App is manually started via arduino-app-cli app start

The http://<UNO Q hostname>:7000 URL seems more intuitive to me than finding a web page is available on localhost even though that page is served by a separate machine on the network.

@ptillisch - @KurtE
Morning just sipping tea and gave it a try first with the streamlit test app and then with the actual vl53 app. Both worked with http://<Uno Q hostname>:7000 URL. Here is a sample from actual app on the rover:

Glad it was a simple solution. Out of curiosity is this documented or did I just miss it? Did you ever think about putting all your fixes you have given people in one one spot - like a Nuts and Bolts write up?

Thanks
Mike

I don't find any documentation about accessing the web app when using the "WebUI - Streamlit" Brick. Something that might be confusing is that we see some seemingly helpful information in the Python Console:

2026-08-04 02:50:32.806 Uvicorn server started on :::7000
You can now view your Streamlit app in your browser.
Local URL: http://localhost:7000
Network URL: http://172.26.0.2:7000
External URL: http://47.146.23.29:7000

My intuition would be that the http://localhost:7000 URL is only usable from a browser running on the board itself. So I don't find that entry too confusing, and in fact was more confused to find that this is the URL Arduino App Lab automagically opened in the browser on my host PC.

The user might expect the web app to be accessible from any machine on the network via the second URL. However, this uses the IP address from inside the container, and thus is not usable from outside the container.

For an App intended to be shared with others, I think it would be a good idea to configure the Python script to print some additional guidance for the user in order to mitigate any confusion that might be caused by the information printed by Streamlit. Of course, instructions should also be provided in the App's documentation, but there is always the chance the user won't read that.

Thanks for the explanation. What confused me is that I see the same type of info:

Local URL: http://localhost:7000
Network URL: http://172.27.0.2:7000
External URL: http://98.116.57.223:7000

but when streamlit opens automatically its using http://172.27.0.2:7000 but I am on a Windows 11 pc. So when I posted I thought this would have been the address.

EDIT: Note I have been keeping a notebook of alot of you comments or a copy for reference so I can go back if I forget :) One of these days when I am board will put it all together in one spot.