Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPython widget for streaming data #435

Open
mrocklin opened this issue Nov 11, 2017 · 5 comments
Open

IPython widget for streaming data #435

mrocklin opened this issue Nov 11, 2017 · 5 comments

Comments

@mrocklin
Copy link

In order to support streaming data it would be convenient to have an IPython widget that gave users the ability to add more rows of data asynchronously.

This arose in conversation with @ellisonbg and @arvind, both of whom I suspect would have more information on how this could be achieved.

@ellisonbg
Copy link
Collaborator

ellisonbg commented Nov 12, 2017 via email

@mrocklin
Copy link
Author

I'm planning an upcoming conference talk (PyData NYC). My guess is that the odds of this being complete one week from now is fairly slim, yes? (this is fine, just need to plan alternate demos).

@ellisonbg
Copy link
Collaborator

ellisonbg commented Nov 21, 2017 via email

@miguelandrs
Copy link

Any updates on the ability to Chart a growing dataframe? Or alternative approaches? Thanks!

@Delaunay
Copy link

Not a IPython widget, but I came up with a way to stream data to vega plots through flask and flask-socketio.
I had to modify the altair javascript entry point to insert a callback to update the data.
From there I could use socketio to send event to update the plot from python in a Thread.

I was able to package it in a simple python function.
Leaving this, hoping it could help

var socket = io();

// Update the vega chart data with new incoming data from the server
appendStreamData = function (id) {
    return function(chart) {
        // Register the event handler
        socket.on('stream_data_' + id, function(data){
            var values = data['new_values'];
            var name = data['name']

            var changeSet = vega
                .changeset()
                .insert(values);

            // log('receiving ' + name + ' ' + values);
            chart.view.change(name, changeSet).run();
        });
        log('stream handler attached');
    }
}

displayVega = function(vegaEmbed, elementId, spec) {
    var embedOpt = {
        "mode": "vega-lite"
    };

    function showError(el, error) {
        el.innerHTML = ('<div class="error" style="color:red;">' +
            '<p>JavaScript Error: ' + error.message + '</p>' +
            "<p>This usually means there's a typo in your chart specification. " +
            "See the javascript console for the full traceback.</p>" +
            '</div>');
        throw error;
    }
    const el = document.getElementById(elementId);

    vegaEmbed("#" + elementId, spec)
        .then(appendStreamData(elementId))
        .catch(error => showError(el, error));
};

displayVega(vegaEmbed, myid, spec)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants