GithubHelp home page GithubHelp logo

roniemartinez / real-time-charts-with-flask Goto Github PK

View Code? Open in Web Editor NEW
73.0 3.0 19.0 280 KB

Sample application for the blog "Creating Real-Time Charts with Flask"

Home Page: https://ron.sh/creating-real-time-charts-with-flask/

License: MIT License

Python 26.06% HTML 62.90% Dockerfile 3.42% Makefile 7.62%
flask python chartjs sse server-sent-events

real-time-charts-with-flask's Introduction

real-time-charts-with-flask's People

Contributors

dependabot[bot] avatar roniemartinez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

real-time-charts-with-flask's Issues

Asking

Hi Ronnie, how r u?

i wanna ask about this code below

@application.route('/chart-data')
def chart_data():
    def generate_random_data():
        while True:
            json_data = json.dumps(
                {'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'value': random.random() * 100})
            yield f"data:{json_data}\n\n"
            time.sleep(1)

    return Response(generate_random_data(), mimetype='text/event-stream')

why you make 2 method/function (chart_data() & generate_random_data()) in this route?

Typo in "/chart-data" (index.html) means graph doesn't find data stream

Hi there,

Thanks for writing this clear example. I noticed that running the code doesn't actually have the intended effect: the graph doesn't update, though if you navigate to /chart_data you can see the JSON data being written.

The reason is you have a small inconsistency between the flask app.py and the index.html template - you go from an underscore to a hyphen in "/chart-data".

Cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.