Update graph on same tab instead another one

how can i display a figure in same tab instead another when i use fig.show() or any method else?

this is my code

import plotly.graph_objects as go

import pandas as pd

from binance.websocket.futures.websocket_client import FuturesWebsocketClient as WebsocketClient

df= pd.read_csv('data')

fig = go.Figure(data=[go.Candlestick(x=df['opentimes'],

                open=df['openprices'],

                high=df['highprices'],

                low=df['lowprices'],

                close=df['closeprices']),

                ])

def message_handler(message):

    Statements to add message to csv..

    #read new csv

    df = pd.read_csv('data_ws')

    #update new candlestick data

    fig.update_traces(patch=dict(x=df['opentimes'],open=df['openprices'],

                high=df['highprices'],

                low=df['lowprices'],

                close=df['closeprices'],

                ),selector=dict(name='main'))

    #

    fig.show() # < ------- at this momement display figure on new tab instead same.

ws_client = WebsocketClient()

ws_client.start()

ws_client.kline(
    symbol='btcusdt',
    interval='1m',
    id=1,
    callback=message_handler, <------callback function every messaga received from socket.
)

and i got a lot tabs in chrome browser instead of refresh data at old and first one.

1 Like