Closed
Description
Context
dash 1.13.4
dash-bootstrap-components 0.10.0
dash-core-components 1.10.1
dash-daq 0.5.0
dash-devices 0.1.2
dash-html-components 1.0.3
dash-renderer 1.5.1
dash-table 4.8.1
- OS: Windows 7 & 10
- Browser: Chrome
Code
from dash import Dash, callback_context
from dash.dependencies import Input, Output
from dash.exceptions import PreventUpdate
from dash_core_components import Graph
from dash_html_components import Div, Button
import pandas as pd
from numpy import nan
import plotly.graph_objs as go
def plot_close(ttype):
if ttype == 'A':
data = [
{'open': 1, 'low': 0, 'close': 0.5, 'high': 2, 'ts': 1,},
]
else:
data = [
{'open': nan, 'low': nan, 'close': nan, 'high': nan, 'ts': 1,},
]
df = pd.DataFrame.from_dict(data)
fig = go.Figure(
[
go.Candlestick(
x=df["ts"],
open=df["open"],
high=df["high"],
low=df["low"],
close=df["close"],
)
]
)
return fig
app = Dash(__name__)
app.layout = Div([Button("A", id='A'), Button("B", id='B'), Graph(id="graph")])
@app.callback(
[Output('graph', 'figure'),], [Input('A', 'n_clicks'), Input('B', 'n_clicks')],
)
def draw_hangqing(bar1, bar4):
id = callback_context.triggered[0]['prop_id'].split('.')[0]
if id == '':
raise PreventUpdate
print("Trigered by", id)
fig = plot_close(id)
return [fig]
app.run_server(host='0.0.0.0', port=8031, debug=False)
Bug
When click on Button A and Button B back and forth repeatedly, you can see there is always a candle bar appearing on the graph which supposedly be empty when click B, 'cause it's data is all nan.