Real time/updating Plotly chart in Python/Flask app?
I built a Webapp with Flask (with a JS frontend) and now i would like to add charts to show my data.
I managed to embed a chart on it but it's static, is there a way to make it dynamic (for example with random values so that i can later add my own data to it)?
def index():
rng = pd.date_range('1/1/2011', periods=7500, freq='H')
ts = pd.Series(np.random.randn(len(rng)), index=rng)
graphs = [
dict(
data=[
dict(
x= arr,
y=[10, 20, 30],
type='scatter'
),
],
layout=dict(
title='first graph'
)
)
]
# Add "ids" to each of the graphs to pass up to the client
# for templating
ids = ['graph-'.format(i) for i, _ in enumerate(graphs)]
# Convert the figures to JSON
# PlotlyJSONEncoder appropriately converts pandas, datetime, etc
# objects to their JSON equivalents
graphJSON = json.dumps(graphs, cls=plotly.utils.PlotlyJSONEncoder)
return render_template('index.html',
ids=ids,
graphJSON=graphJSON)
python plotly
add a comment |
I built a Webapp with Flask (with a JS frontend) and now i would like to add charts to show my data.
I managed to embed a chart on it but it's static, is there a way to make it dynamic (for example with random values so that i can later add my own data to it)?
def index():
rng = pd.date_range('1/1/2011', periods=7500, freq='H')
ts = pd.Series(np.random.randn(len(rng)), index=rng)
graphs = [
dict(
data=[
dict(
x= arr,
y=[10, 20, 30],
type='scatter'
),
],
layout=dict(
title='first graph'
)
)
]
# Add "ids" to each of the graphs to pass up to the client
# for templating
ids = ['graph-'.format(i) for i, _ in enumerate(graphs)]
# Convert the figures to JSON
# PlotlyJSONEncoder appropriately converts pandas, datetime, etc
# objects to their JSON equivalents
graphJSON = json.dumps(graphs, cls=plotly.utils.PlotlyJSONEncoder)
return render_template('index.html',
ids=ids,
graphJSON=graphJSON)
python plotly
Have you seen plotly streaming? plot.ly/python/streaming-tutorial or Dash github.com/plotly/dash-wind-streaming/blob/master/README.md
– cricket_007
Nov 13 '18 at 15:18
Yeah, i looked into Dash and i'm probably going to use it!
– Jack022
Nov 13 '18 at 17:14
add a comment |
I built a Webapp with Flask (with a JS frontend) and now i would like to add charts to show my data.
I managed to embed a chart on it but it's static, is there a way to make it dynamic (for example with random values so that i can later add my own data to it)?
def index():
rng = pd.date_range('1/1/2011', periods=7500, freq='H')
ts = pd.Series(np.random.randn(len(rng)), index=rng)
graphs = [
dict(
data=[
dict(
x= arr,
y=[10, 20, 30],
type='scatter'
),
],
layout=dict(
title='first graph'
)
)
]
# Add "ids" to each of the graphs to pass up to the client
# for templating
ids = ['graph-'.format(i) for i, _ in enumerate(graphs)]
# Convert the figures to JSON
# PlotlyJSONEncoder appropriately converts pandas, datetime, etc
# objects to their JSON equivalents
graphJSON = json.dumps(graphs, cls=plotly.utils.PlotlyJSONEncoder)
return render_template('index.html',
ids=ids,
graphJSON=graphJSON)
python plotly
I built a Webapp with Flask (with a JS frontend) and now i would like to add charts to show my data.
I managed to embed a chart on it but it's static, is there a way to make it dynamic (for example with random values so that i can later add my own data to it)?
def index():
rng = pd.date_range('1/1/2011', periods=7500, freq='H')
ts = pd.Series(np.random.randn(len(rng)), index=rng)
graphs = [
dict(
data=[
dict(
x= arr,
y=[10, 20, 30],
type='scatter'
),
],
layout=dict(
title='first graph'
)
)
]
# Add "ids" to each of the graphs to pass up to the client
# for templating
ids = ['graph-'.format(i) for i, _ in enumerate(graphs)]
# Convert the figures to JSON
# PlotlyJSONEncoder appropriately converts pandas, datetime, etc
# objects to their JSON equivalents
graphJSON = json.dumps(graphs, cls=plotly.utils.PlotlyJSONEncoder)
return render_template('index.html',
ids=ids,
graphJSON=graphJSON)
python plotly
python plotly
asked Nov 13 '18 at 13:52
Jack022Jack022
6510
6510
Have you seen plotly streaming? plot.ly/python/streaming-tutorial or Dash github.com/plotly/dash-wind-streaming/blob/master/README.md
– cricket_007
Nov 13 '18 at 15:18
Yeah, i looked into Dash and i'm probably going to use it!
– Jack022
Nov 13 '18 at 17:14
add a comment |
Have you seen plotly streaming? plot.ly/python/streaming-tutorial or Dash github.com/plotly/dash-wind-streaming/blob/master/README.md
– cricket_007
Nov 13 '18 at 15:18
Yeah, i looked into Dash and i'm probably going to use it!
– Jack022
Nov 13 '18 at 17:14
Have you seen plotly streaming? plot.ly/python/streaming-tutorial or Dash github.com/plotly/dash-wind-streaming/blob/master/README.md
– cricket_007
Nov 13 '18 at 15:18
Have you seen plotly streaming? plot.ly/python/streaming-tutorial or Dash github.com/plotly/dash-wind-streaming/blob/master/README.md
– cricket_007
Nov 13 '18 at 15:18
Yeah, i looked into Dash and i'm probably going to use it!
– Jack022
Nov 13 '18 at 17:14
Yeah, i looked into Dash and i'm probably going to use it!
– Jack022
Nov 13 '18 at 17:14
add a comment |
1 Answer
1
active
oldest
votes
HTTP is stateless by nature, so if you want dynamic, you will have to do that in the frontend.
Without knowing more about your Frontend I cannot give concrete examples,
but hopefully this puts you on the right track:
- Update the chart data in constant intervals through AJAX calls to the backend.
- With that extended data update the chart through
Plotly.extendtraces
Thanks! I'll look into it!
– Jack022
Nov 13 '18 at 17:13
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282548%2freal-time-updating-plotly-chart-in-python-flask-app%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
HTTP is stateless by nature, so if you want dynamic, you will have to do that in the frontend.
Without knowing more about your Frontend I cannot give concrete examples,
but hopefully this puts you on the right track:
- Update the chart data in constant intervals through AJAX calls to the backend.
- With that extended data update the chart through
Plotly.extendtraces
Thanks! I'll look into it!
– Jack022
Nov 13 '18 at 17:13
add a comment |
HTTP is stateless by nature, so if you want dynamic, you will have to do that in the frontend.
Without knowing more about your Frontend I cannot give concrete examples,
but hopefully this puts you on the right track:
- Update the chart data in constant intervals through AJAX calls to the backend.
- With that extended data update the chart through
Plotly.extendtraces
Thanks! I'll look into it!
– Jack022
Nov 13 '18 at 17:13
add a comment |
HTTP is stateless by nature, so if you want dynamic, you will have to do that in the frontend.
Without knowing more about your Frontend I cannot give concrete examples,
but hopefully this puts you on the right track:
- Update the chart data in constant intervals through AJAX calls to the backend.
- With that extended data update the chart through
Plotly.extendtraces
HTTP is stateless by nature, so if you want dynamic, you will have to do that in the frontend.
Without knowing more about your Frontend I cannot give concrete examples,
but hopefully this puts you on the right track:
- Update the chart data in constant intervals through AJAX calls to the backend.
- With that extended data update the chart through
Plotly.extendtraces
answered Nov 13 '18 at 15:13
Sebastian LoehnerSebastian Loehner
72245
72245
Thanks! I'll look into it!
– Jack022
Nov 13 '18 at 17:13
add a comment |
Thanks! I'll look into it!
– Jack022
Nov 13 '18 at 17:13
Thanks! I'll look into it!
– Jack022
Nov 13 '18 at 17:13
Thanks! I'll look into it!
– Jack022
Nov 13 '18 at 17:13
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282548%2freal-time-updating-plotly-chart-in-python-flask-app%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you seen plotly streaming? plot.ly/python/streaming-tutorial or Dash github.com/plotly/dash-wind-streaming/blob/master/README.md
– cricket_007
Nov 13 '18 at 15:18
Yeah, i looked into Dash and i'm probably going to use it!
– Jack022
Nov 13 '18 at 17:14