Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

How to display the value of a variable in plotly python?

Already having made multiple plots using plotly-python, I wish to do a rather simple task: Display the value of a variable in the HTML output page.

Imagine a number (in large font) on the top of the dashboard below showing the total costs . Any help would be much appreciated!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Although it would be much more helpful if you showed us your code, an easy solution to your problem is to have an HTML.div in the layout and set it with an id, and with the corresponding ID, create a callback with the ID as the output that returns the value of the variable.

An example:

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output


app = dash.Dash(__name__)

app.layout = html.Div([
    html.Div(id='my-output'),
    html.Div(id='my-output'),

])

x = "hi"

@app.callback(
    Output(component_id='my-output', component_property='children'),
    Input(component_id='my-input', component_property='children')
)
def update_output_div(input):
    return x


if __name__ == '__main__':
    app.run_server(debug=True)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...