Plotly gauge overwriting itself

Hi everyone…

Summary

I added a gauge to my dash using plotly and after some prints it starts to overwrite itself.

Steps to reproduce

Its a dynamic gauge, so the limits and values will change every pass.

import streamlit as st
import plotly.graph_objects as go

        fig.add_trace(go.Indicator(
            mode="gauge+number+delta",
            title = {'text': "price"},
            delta = {'reference': ask_price, 'relative': False, 'increasing': {'color': "RebeccaPurple"}, 'decreasing': {'color': "RoyalBlue"}},
            value = current_price,
            domain={'x': [0, 1], 'y': [0, 1]},
            gauge={
                'shape': 'angular',
                'axis': {'range': [bid_price - spread, ask_price + spread]},
                #'axis': {'range': [lower_limit, upper_limit]},
                'bar': {'color': "darkblue"},
                'bgcolor': 'yellow',
                'borderwidth': 2,
                'bordercolor': 'black',
                'steps': [
                    {'range': [bid_price*0.9 , bid_price], 'color': 'green'},
                    {'range': [ask_price , ask_price*1.1], 'color': 'red'}
                ],
                'threshold': {
                    'line': {'color': 'orange', 'width': 6},
                    'thickness': 0.75,
                    'value': current_price,
                }
            },
            #number={'prefix': 'BTC'}
        ))
        
        # Adjust the width and height of the gauge
        #fig.update_layout(height=500, width=800)
        with fig_placeholder:
                #st.plotly_chart(fig, theme="streamlit", use_container_width=True)
                st.plotly_chart(fig, use_container_width=True)
                #st.plotly_chart(fig)

Expected behavior:

It should always print the new info without keeping the old one…

Debug info

  • Streamlit version: Streamlit, version 1.24.0
  • Python version: Python 3.8.5
  • venv
  • OS version: Debian GNU/Linux 10 (buster)
  • Browser version: Version 114.0.5735.199 (Official Build) (64-bit)

Screenshot 2023-07-05 224408

1 Like

Solved, just initialize the fig object each time before updating the gauge.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.