[bokehJS] - minimal example updating line plot with json data

Hi all,

I’m trying to make a minimal example of a line plot, that takes an external json content and plots it. I first would like just to load the json, not really have to rely on the bokeh-server or anything else… Once this is done, I want to be able to update the plot (say, click a button, multiply all elements from the data by 2, and update the view) … ?

Any hint ?

Thanks a lot,

Tom

Hi Thomas,

Right now Bokeh plots are only reactive from the updates from the server. Without the server, coupling a button press to "multiply all values by two" means that that data update has to happen purely in JavaScript. Perhaps we could think about exposing some kind of plug in system that allows events to be bound to arbitrary snippets of javascript, but there is no functionality for that currently.

Bryan

···

On Apr 29, 2014, at 6:35 AM, Thomas Lecocq <[email protected]> wrote:

Hi all,

I'm trying to make a minimal example of a line plot, that takes an external json content and plots it. I first would like just to load the json, not really have to rely on the bokeh-server or anything else... Once this is done, I want to be able to update the plot (say, click a button, multiply all elements from the data by 2, and update the view) ... ?

Any hint ?

Thanks a lot,

Tom

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/6727a554-3420-4e33-b676-85a3ccef2273%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Bryan,

Thanks for your comment.

I managed to expose almost enough of what I need… Could you just tell me how to trigger an update of the x_range,y_range, so the view fits the data added ?

Thanks

line.py example $(function() { data = {"attributes": {"column_names": ["x", "y"], "doc": null, "selected": [], "discrete_ranges": {}, "cont_ranges": {}, "data": {"y": [0.0, ], "x": [0.0, ]}, "id": "data"}, "type": "ColumnDataSource", "id": "data"}, all_models = [ data,
            {"attributes": {"sources": [{"source": {"type": "ColumnDataSource", "id": "data"}, "columns": ["x"]}], "id": "bbd5dd00-5564-4e65-9169-5c149e857686", "doc": null}, "type": "DataRange1d", "id": "bbd5dd00-5564-4e65-9169-5c149e857686"},
           
            {"attributes": {"sources": [{"source": {"type": "ColumnDataSource", "id": "data"}, "columns": ["y"]}], "id": "fc8abecf-9289-4f8d-8b60-ee9b834a46aa", "doc": null}, "type": "DataRange1d", "id": "fc8abecf-9289-4f8d-8b60-ee9b834a46aa"},
           
            {"attributes": {"doc": null, "id": "88360242-94ef-4839-abb4-d302553810d2"}, "type": "BasicTickFormatter", "id": "88360242-94ef-4839-abb4-d302553810d2"},
            {"attributes": {"doc": null, "id": "8deaa0b1-cab2-47b3-8674-67f6ebfac56b"}, "type": "BasicTicker", "id": "8deaa0b1-cab2-47b3-8674-67f6ebfac56b"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "bounds": "auto", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560", "location": "min", "formatter": {"type": "BasicTickFormatter", "id": "88360242-94ef-4839-abb4-d302553810d2"}, "ticker": {"type": "BasicTicker", "id": "8deaa0b1-cab2-47b3-8674-67f6ebfac56b"}, "dimension": 0}, "type": "LinearAxis", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "axis": {"type": "LinearAxis", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560"}, "id": "5a329fd3-154a-4ed5-a7a2-764384e3c1af", "dimension": 0}, "type": "Grid", "id": "5a329fd3-154a-4ed5-a7a2-764384e3c1af"},
            {"attributes": {"doc": null, "id": "7a9415cc-8ed2-459a-b51a-8bdb79ff282e"}, "type": "BasicTickFormatter", "id": "7a9415cc-8ed2-459a-b51a-8bdb79ff282e"},
            {"attributes": {"doc": null, "id": "f83ecaba-e25f-42f9-abfa-f060af866bdf"}, "type": "BasicTicker", "id": "f83ecaba-e25f-42f9-abfa-f060af866bdf"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "bounds": "auto", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e", "location": "min", "formatter": {"type": "BasicTickFormatter", "id": "7a9415cc-8ed2-459a-b51a-8bdb79ff282e"}, "ticker": {"type": "BasicTicker", "id": "f83ecaba-e25f-42f9-abfa-f060af866bdf"}, "dimension": 1}, "type": "LinearAxis", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "id": "91b7f168-6022-4019-98a9-31e6cd989671", "doc": null}, "type": "BoxZoomTool", "id": "91b7f168-6022-4019-98a9-31e6cd989671"},
            {"attributes": {"doc": null, "tool": {"type": "BoxZoomTool", "id": "91b7f168-6022-4019-98a9-31e6cd989671"}, "id": "c7af6b67-7298-4431-8000-4268b08e1ada"}, "type": "BoxSelection", "id": "c7af6b67-7298-4431-8000-4268b08e1ada"},
            {"attributes": {"data_source": {"type": "ColumnDataSource", "id": "data"}, "server_data_source": null, "doc": null, "nonselection_glyphspec": {"line_color": {"value": "#1f77b4"}, "line_width": {"units": "data", "field": "line_width"}, "angle_units": "deg", "x": {"units": "data", "field": "x"}, "type": "line", "y": {"units": "data", "field": "y"}, "line_alpha": {"units": "data", "value": 0.1}, "start_angle_units": "deg", "valign": null, "radius_units": "screen", "visible": null, "end_angle_units": "deg", "line_dash_offset": 0, "length_units": "screen", "line_cap": "butt", "line_dash": [], "margin": null, "line_join": "miter", "halign": null}, "xdata_range": null, "ydata_range": null, "glyphspec": {"line_color": {"value": "#0000FF"}, "line_alpha": {"units": "data", "value": 1.0}, "line_width": {"units": "data", "field": "line_width"}, "y": {"units": "data", "field": "y"}, "x": {"units": "data", "field": "x"}, "type": "line"}, "id": "2de55bd4-b714-4283-afd1-e443a04e906f"}, "type": "Glyph", "id": "2de55bd4-b714-4283-afd1-e443a04e906f"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "dimensions": ["width", "height"], "doc": null, "id": "06a57c95-fe07-4033-aee3-32e3d25afe19"}, "type": "PanTool", "id": "06a57c95-fe07-4033-aee3-32e3d25afe19"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "dimensions": ["width", "height"], "doc": null, "id": "b930820a-c2e7-427e-9bd4-501b709e346e"}, "type": "WheelZoomTool", "id": "b930820a-c2e7-427e-9bd4-501b709e346e"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "id": "d3013d8a-0524-4c87-a664-f78a06a3ff77", "doc": null}, "type": "ResetTool", "id": "d3013d8a-0524-4c87-a664-f78a06a3ff77"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "id": "77aa37cd-53c8-4d9d-998b-b9124f92c7ed", "doc": null}, "type": "PreviewSaveTool", "id": "77aa37cd-53c8-4d9d-998b-b9124f92c7ed"},
            {"attributes": {"outer_height": 600, "x_range": {"type": "DataRange1d", "id": "bbd5dd00-5564-4e65-9169-5c149e857686"}, "y_range": {"type": "DataRange1d", "id": "fc8abecf-9289-4f8d-8b60-ee9b834a46aa"}, "outer_width": 600, "renderers": [{"type": "LinearAxis", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560"}, {"type": "Grid", "id": "5a329fd3-154a-4ed5-a7a2-764384e3c1af"}, {"type": "LinearAxis", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e"}, {"type": "Grid", "id": "fac9970a-b9f6-443c-b412-83974d2528d3"}, {"type": "BoxSelection", "id": "c7af6b67-7298-4431-8000-4268b08e1ada"}, {"type": "Glyph", "id": "2de55bd4-b714-4283-afd1-e443a04e906f"}], "id": "line_example", "data_sources": [], "doc": null, "canvas_height": 600, "title": "Plot", "tools": [{"type": "PanTool", "id": "06a57c95-fe07-4033-aee3-32e3d25afe19"}, {"type": "WheelZoomTool", "id": "b930820a-c2e7-427e-9bd4-501b709e346e"}, {"type": "BoxZoomTool", "id": "91b7f168-6022-4019-98a9-31e6cd989671"}, {"type": "ResetTool", "id": "d3013d8a-0524-4c87-a664-f78a06a3ff77"}, {"type": "PreviewSaveTool", "id": "77aa37cd-53c8-4d9d-998b-b9124f92c7ed"}], "canvas_width": 600}, "type": "Plot", "id": "line_example"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "axis": {"type": "LinearAxis", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e"}, "id": "fac9970a-b9f6-443c-b412-83974d2528d3", "dimension": 1}, "type": "Grid", "id": "fac9970a-b9f6-443c-b412-83974d2528d3"},
            {"attributes": {"doc": null, "children": [{"type": "Plot", "id": "line_example"}], "id": "59ac3505-c899-4aeb-bc31-94f5a00e38a8"}, "type": "PlotContext", "id": "59ac3505-c899-4aeb-bc31-94f5a00e38a8"}];
           
            var modelid = "59ac3505-c899-4aeb-bc31-94f5a00e38a8";
            var modeltype = "PlotContext";
            var elementid = "CCF";
            console.log(modelid, modeltype, elementid);
            Bokeh.load_models(all_models);
            model = Bokeh.Collections(modeltype).get(modelid);
            view = new model.default_view({model: model, el: '#CCF'});
        });
    </script>
<script>
$(document).ready(function() {
    $( "#update" ).click(function() {
    data.attributes.data.x = [0,2,5]
        data.attributes.data.y = [0,2,5]
        view = new model.default_view({model: model, el: '#CCF'})
        });
});
</script>
</head>
<body>
    <div class="plotdiv" id="CCF">Plots</div>
    <div id="update" name='update'>

Click here

</body>
···

Le mardi 29 avril 2014 16:17:26 UTC+2, Bryan Van de ven a écrit :

Hi Thomas,

Right now Bokeh plots are only reactive from the updates from the server. Without the server, coupling a button press to “multiply all values by two” means that that data update has to happen purely in JavaScript. Perhaps we could think about exposing some kind of plug in system that allows events to be bound to arbitrary snippets of javascript, but there is no functionality for that currently.

Bryan

On Apr 29, 2014, at 6:35 AM, Thomas Lecocq [email protected] wrote:

Hi all,

I’m trying to make a minimal example of a line plot, that takes an external json content and plots it. I first would like just to load the json, not really have to rely on the bokeh-server or anything else… Once this is done, I want to be able to update the plot (say, click a button, multiply all elements from the data by 2, and update the view) … ?

Any hint ?

Thanks a lot,

Tom


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/6727a554-3420-4e33-b676-85a3ccef2273%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Thomas,

From BokehJS, you will need to trigger some change updates on the source by hand (would love to make this simpler, open to input). Check out the animated BokehJS jsfiddle:

  http://jsfiddle.net/bokeh/K8P4P/

Particularly the "update" function at the end:

update = () ->
  data = window.source.get('data')
  rmin = data["inner_radius"]
  tmp = [rmin[rmin.length-1]].concat(rmin.slice(0, -1))
  data["inner_radius"] = tmp
  rmax = data["outer_radius"]
  tmp = rmax.slice(1).concat([rmax[0]])
  data["outer_radius"] = tmp
  window.source.set('data', data)
  window.source.trigger('change', source, {})

The basic idea is that you need to grab a handle to the DataSource (in that example it's window.source but you will need to pull it out of your plot) and then use .set and .trigger to cause the redraw.

It suddenly occurs to me that this is a use-case I don't think had been considered: hybrid python+js dev. You could use python to easily generate the basic plot but then if you already have js pulling data in from somewhere, you could update the plot from js directly if the datasources, etc., are easily gotten ahold of. That seems pretty neat I will make an issue to explore this idea. Please let me know if you still need more info, or have ideas about this kind of use of Bokeh.

Thanks,

Bryan

···

On Apr 29, 2014, at 10:35 AM, Thomas Lecocq <[email protected]> wrote:

Bryan,

Thanks for your comment.

I managed to expose almost enough of what I need... Could you just tell me how to trigger an update of the x_range,y_range, so the view fits the data added ?

Thanks

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>line.py example</title>
        <link rel="stylesheet" href="http://cdn.pydata.org/bokeh-0.4.4.min.css&quot; type="text/css" />
        <script type="text/javascript" src="http://cdn.pydata.org/bokeh-0.4.4.min.js&quot;&gt;&lt;/script&gt;
        <script src="//code.jquery.com/jquery-1.10.2.js"></script>
        <script type="text/javascript">
            \(function\(\) \{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data = \{&quot;attributes&quot;: \{&quot;column\_names&quot;: \[&quot;x&quot;, &quot;y&quot;\], &quot;doc&quot;: null, &quot;selected&quot;: \[\], &quot;discrete\_ranges&quot;: \{\}, &quot;cont\_ranges&quot;: \{\}, &quot;data&quot;: \{&quot;y&quot;: \[0\.0, \], &quot;x&quot;: \[0\.0, \]\}, &quot;id&quot;: &quot;data&quot;\}, &quot;type&quot;: &quot;ColumnDataSource&quot;, &quot;id&quot;: &quot;data&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;all\_models = \[ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;sources&quot;: \[\{&quot;source&quot;: \{&quot;type&quot;: &quot;ColumnDataSource&quot;, &quot;id&quot;: &quot;data&quot;\}, &quot;columns&quot;: \[&quot;x&quot;\]\}\], &quot;id&quot;: &quot;bbd5dd00\-5564\-4e65\-9169\-5c149e857686&quot;, &quot;doc&quot;: null\}, &quot;type&quot;: &quot;DataRange1d&quot;, &quot;id&quot;: &quot;bbd5dd00\-5564\-4e65\-9169\-5c149e857686&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;sources&quot;: \[\{&quot;source&quot;: \{&quot;type&quot;: &quot;ColumnDataSource&quot;, &quot;id&quot;: &quot;data&quot;\}, &quot;columns&quot;: \[&quot;y&quot;\]\}\], &quot;id&quot;: &quot;fc8abecf\-9289\-4f8d\-8b60\-ee9b834a46aa&quot;, &quot;doc&quot;: null\}, &quot;type&quot;: &quot;DataRange1d&quot;, &quot;id&quot;: &quot;fc8abecf\-9289\-4f8d\-8b60\-ee9b834a46aa&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;doc&quot;: null, &quot;id&quot;: &quot;88360242\-94ef\-4839\-abb4\-d302553810d2&quot;\}, &quot;type&quot;: &quot;BasicTickFormatter&quot;, &quot;id&quot;: &quot;88360242\-94ef\-4839\-abb4\-d302553810d2&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;doc&quot;: null, &quot;id&quot;: &quot;8deaa0b1\-cab2\-47b3\-8674\-67f6ebfac56b&quot;\}, &quot;type&quot;: &quot;BasicTicker&quot;, &quot;id&quot;: &quot;8deaa0b1\-cab2\-47b3\-8674\-67f6ebfac56b&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;doc&quot;: null, &quot;bounds&quot;: &quot;auto&quot;, &quot;id&quot;: &quot;cca1aab2\-4f92\-40cd\-bc26\-cc6d71b18560&quot;, &quot;location&quot;: &quot;min&quot;, &quot;formatter&quot;: \{&quot;type&quot;: &quot;BasicTickFormatter&quot;, &quot;id&quot;: &quot;88360242\-94ef\-4839\-abb4\-d302553810d2&quot;\}, &quot;ticker&quot;: \{&quot;type&quot;: &quot;BasicTicker&quot;, &quot;id&quot;: &quot;8deaa0b1\-cab2\-47b3\-8674\-67f6ebfac56b&quot;\}, &quot;dimension&quot;: 0\}, &quot;type&quot;: &quot;LinearAxis&quot;, &quot;id&quot;: &quot;cca1aab2\-4f92\-40cd\-bc26\-cc6d71b18560&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;doc&quot;: null, &quot;axis&quot;: \{&quot;type&quot;: &quot;LinearAxis&quot;, &quot;id&quot;: &quot;cca1aab2\-4f92\-40cd\-bc26\-cc6d71b18560&quot;\}, &quot;id&quot;: &quot;5a329fd3\-154a\-4ed5\-a7a2\-764384e3c1af&quot;, &quot;dimension&quot;: 0\}, &quot;type&quot;: &quot;Grid&quot;, &quot;id&quot;: &quot;5a329fd3\-154a\-4ed5\-a7a2\-764384e3c1af&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;doc&quot;: null, &quot;id&quot;: &quot;7a9415cc\-8ed2\-459a\-b51a\-8bdb79ff282e&quot;\}, &quot;type&quot;: &quot;BasicTickFormatter&quot;, &quot;id&quot;: &quot;7a9415cc\-8ed2\-459a\-b51a\-8bdb79ff282e&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;doc&quot;: null, &quot;id&quot;: &quot;f83ecaba\-e25f\-42f9\-abfa\-f060af866bdf&quot;\}, &quot;type&quot;: &quot;BasicTicker&quot;, &quot;id&quot;: &quot;f83ecaba\-e25f\-42f9\-abfa\-f060af866bdf&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;doc&quot;: null, &quot;bounds&quot;: &quot;auto&quot;, &quot;id&quot;: &quot;85d7a783\-bc12\-42cc\-8d6f\-89ddb3d2458e&quot;, &quot;location&quot;: &quot;min&quot;, &quot;formatter&quot;: \{&quot;type&quot;: &quot;BasicTickFormatter&quot;, &quot;id&quot;: &quot;7a9415cc\-8ed2\-459a\-b51a\-8bdb79ff282e&quot;\}, &quot;ticker&quot;: \{&quot;type&quot;: &quot;BasicTicker&quot;, &quot;id&quot;: &quot;f83ecaba\-e25f\-42f9\-abfa\-f060af866bdf&quot;\}, &quot;dimension&quot;: 1\}, &quot;type&quot;: &quot;LinearAxis&quot;, &quot;id&quot;: &quot;85d7a783\-bc12\-42cc\-8d6f\-89ddb3d2458e&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;id&quot;: &quot;91b7f168\-6022\-4019\-98a9\-31e6cd989671&quot;, &quot;doc&quot;: null\}, &quot;type&quot;: &quot;BoxZoomTool&quot;, &quot;id&quot;: &quot;91b7f168\-6022\-4019\-98a9\-31e6cd989671&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;doc&quot;: null, &quot;tool&quot;: \{&quot;type&quot;: &quot;BoxZoomTool&quot;, &quot;id&quot;: &quot;91b7f168\-6022\-4019\-98a9\-31e6cd989671&quot;\}, &quot;id&quot;: &quot;c7af6b67\-7298\-4431\-8000\-4268b08e1ada&quot;\}, &quot;type&quot;: &quot;BoxSelection&quot;, &quot;id&quot;: &quot;c7af6b67\-7298\-4431\-8000\-4268b08e1ada&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;data\_source&quot;: \{&quot;type&quot;: &quot;ColumnDataSource&quot;, &quot;id&quot;: &quot;data&quot;\}, &quot;server\_data\_source&quot;: null, &quot;doc&quot;: null, &quot;nonselection\_glyphspec&quot;: \{&quot;line\_color&quot;: \{&quot;value&quot;: &quot;\#1f77b4&quot;\}, &quot;line\_width&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;field&quot;: &quot;line\_width&quot;\}, &quot;angle\_units&quot;: &quot;deg&quot;, &quot;x&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;field&quot;: &quot;x&quot;\}, &quot;type&quot;: &quot;line&quot;, &quot;y&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;field&quot;: &quot;y&quot;\}, &quot;line\_alpha&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;value&quot;: 0\.1\}, &quot;start\_angle\_units&quot;: &quot;deg&quot;, &quot;valign&quot;: null, &quot;radius\_units&quot;: &quot;screen&quot;, &quot;visible&quot;: null, &quot;end\_angle\_units&quot;: &quot;deg&quot;, &quot;line\_dash\_offset&quot;: 0, &quot;length\_units&quot;: &quot;screen&quot;, &quot;line\_cap&quot;: &quot;butt&quot;, &quot;line\_dash&quot;: \[\], &quot;margin&quot;: null, &quot;line\_join&quot;: &quot;miter&quot;, &quot;halign&quot;: null\}, &quot;xdata\_range&quot;: null, &quot;ydata\_range&quot;: null, &quot;glyphspec&quot;: \{&quot;line\_color&quot;: \{&quot;value&quot;: &quot;\#0000FF&quot;\}, &quot;line\_alpha&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;value&quot;: 1\.0\}, &quot;line\_width&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;field&quot;: &quot;line\_width&quot;\}, &quot;y&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;field&quot;: &quot;y&quot;\}, &quot;x&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;field&quot;: &quot;x&quot;\}, &quot;type&quot;: &quot;line&quot;\}, &quot;id&quot;: &quot;2de55bd4\-b714\-4283\-afd1\-e443a04e906f&quot;\}, &quot;type&quot;: &quot;Glyph&quot;, &quot;id&quot;: &quot;2de55bd4\-b714\-4283\-afd1\-e443a04e906f&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;dimensions&quot;: \[&quot;width&quot;, &quot;height&quot;\], &quot;doc&quot;: null, &quot;id&quot;: &quot;06a57c95\-fe07\-4033\-aee3\-32e3d25afe19&quot;\}, &quot;type&quot;: &quot;PanTool&quot;, &quot;id&quot;: &quot;06a57c95\-fe07\-4033\-aee3\-32e3d25afe19&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;dimensions&quot;: \[&quot;width&quot;, &quot;height&quot;\], &quot;doc&quot;: null, &quot;id&quot;: &quot;b930820a\-c2e7\-427e\-9bd4\-501b709e346e&quot;\}, &quot;type&quot;: &quot;WheelZoomTool&quot;, &quot;id&quot;: &quot;b930820a\-c2e7\-427e\-9bd4\-501b709e346e&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;id&quot;: &quot;d3013d8a\-0524\-4c87\-a664\-f78a06a3ff77&quot;, &quot;doc&quot;: null\}, &quot;type&quot;: &quot;ResetTool&quot;, &quot;id&quot;: &quot;d3013d8a\-0524\-4c87\-a664\-f78a06a3ff77&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;id&quot;: &quot;77aa37cd\-53c8\-4d9d\-998b\-b9124f92c7ed&quot;, &quot;doc&quot;: null\}, &quot;type&quot;: &quot;PreviewSaveTool&quot;, &quot;id&quot;: &quot;77aa37cd\-53c8\-4d9d\-998b\-b9124f92c7ed&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;outer\_height&quot;: 600, &quot;x\_range&quot;: \{&quot;type&quot;: &quot;DataRange1d&quot;, &quot;id&quot;: &quot;bbd5dd00\-5564\-4e65\-9169\-5c149e857686&quot;\}, &quot;y\_range&quot;: \{&quot;type&quot;: &quot;DataRange1d&quot;, &quot;id&quot;: &quot;fc8abecf\-9289\-4f8d\-8b60\-ee9b834a46aa&quot;\}, &quot;outer\_width&quot;: 600, &quot;renderers&quot;: \[\{&quot;type&quot;: &quot;LinearAxis&quot;, &quot;id&quot;: &quot;cca1aab2\-4f92\-40cd\-bc26\-cc6d71b18560&quot;\}, \{&quot;type&quot;: &quot;Grid&quot;, &quot;id&quot;: &quot;5a329fd3\-154a\-4ed5\-a7a2\-764384e3c1af&quot;\}, \{&quot;type&quot;: &quot;LinearAxis&quot;, &quot;id&quot;: &quot;85d7a783\-bc12\-42cc\-8d6f\-89ddb3d2458e&quot;\}, \{&quot;type&quot;: &quot;Grid&quot;, &quot;id&quot;: &quot;fac9970a\-b9f6\-443c\-b412\-83974d2528d3&quot;\}, \{&quot;type&quot;: &quot;BoxSelection&quot;, &quot;id&quot;: &quot;c7af6b67\-7298\-4431\-8000\-4268b08e1ada&quot;\}, \{&quot;type&quot;: &quot;Glyph&quot;, &quot;id&quot;: &quot;2de55bd4\-b714\-4283\-afd1\-e443a04e906f&quot;\}\], &quot;id&quot;: &quot;line\_example&quot;, &quot;data\_sources&quot;: \[\], &quot;doc&quot;: null, &quot;canvas\_height&quot;: 600, &quot;title&quot;: &quot;Plot&quot;, &quot;tools&quot;: \[\{&quot;type&quot;: &quot;PanTool&quot;, &quot;id&quot;: &quot;06a57c95\-fe07\-4033\-aee3\-32e3d25afe19&quot;\}, \{&quot;type&quot;: &quot;WheelZoomTool&quot;, &quot;id&quot;: &quot;b930820a\-c2e7\-427e\-9bd4\-501b709e346e&quot;\}, \{&quot;type&quot;: &quot;BoxZoomTool&quot;, &quot;id&quot;: &quot;91b7f168\-6022\-4019\-98a9\-31e6cd989671&quot;\}, \{&quot;type&quot;: &quot;ResetTool&quot;, &quot;id&quot;: &quot;d3013d8a\-0524\-4c87\-a664\-f78a06a3ff77&quot;\}, \{&quot;type&quot;: &quot;PreviewSaveTool&quot;, &quot;id&quot;: &quot;77aa37cd\-53c8\-4d9d\-998b\-b9124f92c7ed&quot;\}\], &quot;canvas\_width&quot;: 600\}, &quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;doc&quot;: null, &quot;axis&quot;: \{&quot;type&quot;: &quot;LinearAxis&quot;, &quot;id&quot;: &quot;85d7a783\-bc12\-42cc\-8d6f\-89ddb3d2458e&quot;\}, &quot;id&quot;: &quot;fac9970a\-b9f6\-443c\-b412\-83974d2528d3&quot;, &quot;dimension&quot;: 1\}, &quot;type&quot;: &quot;Grid&quot;, &quot;id&quot;: &quot;fac9970a\-b9f6\-443c\-b412\-83974d2528d3&quot;\}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{&quot;attributes&quot;: \{&quot;doc&quot;: null, &quot;children&quot;: \[\{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}\], &quot;id&quot;: &quot;59ac3505\-c899\-4aeb\-bc31\-94f5a00e38a8&quot;\}, &quot;type&quot;: &quot;PlotContext&quot;, &quot;id&quot;: &quot;59ac3505\-c899\-4aeb\-bc31\-94f5a00e38a8&quot;\}\]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var modelid = &quot;59ac3505\-c899\-4aeb\-bc31\-94f5a00e38a8&quot;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var modeltype = &quot;PlotContext&quot;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var elementid = &quot;CCF&quot;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console\.log\(modelid, modeltype, elementid\); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bokeh\.load\_models\(all\_models\); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model = Bokeh\.Collections\(modeltype\)\.get\(modelid\); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;view = new model\.default\_view\(\{model: model, el: &#39;\#CCF&#39;\}\); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\}\); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/script&gt; &nbsp;&nbsp;&nbsp;&nbsp;&lt;script&gt; &nbsp;&nbsp;&nbsp;&nbsp;(document).ready(function() {
        $( "#update" ).click(function() {
        data.attributes.data.x = [0,2,5]
            data.attributes.data.y = [0,2,5]
            view = new model.default_view({model: model, el: '#CCF'})
            });
    });
    </script>
    </head>
    <body>
        <div class="plotdiv" id="CCF">Plots</div>
        <div id="update" name='update'>
Click here
</div>
        
    </body>
</html>

Le mardi 29 avril 2014 16:17:26 UTC+2, Bryan Van de ven a écrit :
Hi Thomas,

Right now Bokeh plots are only reactive from the updates from the server. Without the server, coupling a button press to "multiply all values by two" means that that data update has to happen purely in JavaScript. Perhaps we could think about exposing some kind of plug in system that allows events to be bound to arbitrary snippets of javascript, but there is no functionality for that currently.

Bryan

On Apr 29, 2014, at 6:35 AM, Thomas Lecocq <[email protected]> wrote:

> Hi all,
>
> I'm trying to make a minimal example of a line plot, that takes an external json content and plots it. I first would like just to load the json, not really have to rely on the bokeh-server or anything else... Once this is done, I want to be able to update the plot (say, click a button, multiply all elements from the data by 2, and update the view) ... ?
>
> Any hint ?
>
> Thanks a lot,
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/6727a554-3420-4e33-b676-85a3ccef2273%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/f1f888f9-c084-4a31-a748-dda332b568e3%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi Bryan,

Digging into the JS code, I think I found some ways of updating the {x,y}_ranges on the view, which are not updated when I trigger the ‘change’ on the model.

Hope this gives new ideas :slight_smile: Next step: get x,y data from an $.ajax call :slight_smile:

Cheers,

Thom

Animated - jsFiddle demo by bokeh

Le mardi 29 avril 2014 17:44:54 UTC+2, Bryan Van de ven a écrit :

Thomas,

From BokehJS, you will need to trigger some change updates on the source by hand (would love to make this simpler, open to input). Check out the animated BokehJS jsfiddle:

    [http://jsfiddle.net/bokeh/K8P4P/](http://jsfiddle.net/bokeh/K8P4P/)

Particularly the “update” function at the end:

update = () →

data = window.source.get(‘data’)

rmin = data[“inner_radius”]

tmp = [rmin[rmin.length-1]].concat(rmin.slice(0, -1))

data[“inner_radius”] = tmp

rmax = data[“outer_radius”]

tmp = rmax.slice(1).concat([rmax[0]])

data[“outer_radius”] = tmp

window.source.set(‘data’, data)

window.source.trigger(‘change’, source, {})

The basic idea is that you need to grab a handle to the DataSource (in that example it’s window.source but you will need to pull it out of your plot) and then use .set and .trigger to cause the redraw.

It suddenly occurs to me that this is a use-case I don’t think had been considered: hybrid python+js dev. You could use python to easily generate the basic plot but then if you already have js pulling data in from somewhere, you could update the plot from js directly if the datasources, etc., are easily gotten ahold of. That seems pretty neat I will make an issue to explore this idea. Please let me know if you still need more info, or have ideas about this kind of use of Bokeh.

Thanks,

Bryan

On Apr 29, 2014, at 10:35 AM, Thomas Lecocq [email protected] wrote:

Bryan,

Thanks for your comment.

I managed to expose almost enough of what I need… Could you just tell me how to trigger an update of the x_range,y_range, so the view fits the data added ?

Thanks

<head>
    <meta charset="utf-8">
    <title>line.py example</title>
    <link rel="stylesheet" href="[http://cdn.pydata.org/bokeh-0.4.4.min.css](http://cdn.pydata.org/bokeh-0.4.4.min.css)" type="text/css" />
    <script type="text/javascript" src="[http://cdn.pydata.org/bokeh-0.4.4.min.js](http://cdn.pydata.org/bokeh-0.4.4.min.js)"></script>
    <script src="//[code.jquery.com/jquery-1.10.2.js](http://code.jquery.com/jquery-1.10.2.js)"></script>
    <script type="text/javascript">
        $(function() {
            data = {"attributes": {"column_names": ["x", "y"], "doc": null, "selected": [], "discrete_ranges": {}, "cont_ranges": {}, "data": {"y": [0.0, ], "x": [0.0, ]}, "id": "data"}, "type": "ColumnDataSource", "id": "data"},
            all_models = [
            data,
            {"attributes": {"sources": [{"source": {"type": "ColumnDataSource", "id": "data"}, "columns": ["x"]}], "id": "bbd5dd00-5564-4e65-9169-5c149e857686", "doc": null}, "type": "DataRange1d", "id": "bbd5dd00-5564-4e65-9169-5c149e857686"},
           
            {"attributes": {"sources": [{"source": {"type": "ColumnDataSource", "id": "data"}, "columns": ["y"]}], "id": "fc8abecf-9289-4f8d-8b60-ee9b834a46aa", "doc": null}, "type": "DataRange1d", "id": "fc8abecf-9289-4f8d-8b60-ee9b834a46aa"},
           
            {"attributes": {"doc": null, "id": "88360242-94ef-4839-abb4-d302553810d2"}, "type": "BasicTickFormatter", "id": "88360242-94ef-4839-abb4-d302553810d2"},
            {"attributes": {"doc": null, "id": "8deaa0b1-cab2-47b3-8674-67f6ebfac56b"}, "type": "BasicTicker", "id": "8deaa0b1-cab2-47b3-8674-67f6ebfac56b"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "bounds": "auto", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560", "location": "min", "formatter": {"type": "BasicTickFormatter", "id": "88360242-94ef-4839-abb4-d302553810d2"}, "ticker": {"type": "BasicTicker", "id": "8deaa0b1-cab2-47b3-8674-67f6ebfac56b"}, "dimension": 0}, "type": "LinearAxis", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "axis": {"type": "LinearAxis", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560"}, "id": "5a329fd3-154a-4ed5-a7a2-764384e3c1af", "dimension": 0}, "type": "Grid", "id": "5a329fd3-154a-4ed5-a7a2-764384e3c1af"},
            {"attributes": {"doc": null, "id": "7a9415cc-8ed2-459a-b51a-8bdb79ff282e"}, "type": "BasicTickFormatter", "id": "7a9415cc-8ed2-459a-b51a-8bdb79ff282e"},
            {"attributes": {"doc": null, "id": "f83ecaba-e25f-42f9-abfa-f060af866bdf"}, "type": "BasicTicker", "id": "f83ecaba-e25f-42f9-abfa-f060af866bdf"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "bounds": "auto", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e", "location": "min", "formatter": {"type": "BasicTickFormatter", "id": "7a9415cc-8ed2-459a-b51a-8bdb79ff282e"}, "ticker": {"type": "BasicTicker", "id": "f83ecaba-e25f-42f9-abfa-f060af866bdf"}, "dimension": 1}, "type": "LinearAxis", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "id": "91b7f168-6022-4019-98a9-31e6cd989671", "doc": null}, "type": "BoxZoomTool", "id": "91b7f168-6022-4019-98a9-31e6cd989671"},
            {"attributes": {"doc": null, "tool": {"type": "BoxZoomTool", "id": "91b7f168-6022-4019-98a9-31e6cd989671"}, "id": "c7af6b67-7298-4431-8000-4268b08e1ada"}, "type": "BoxSelection", "id": "c7af6b67-7298-4431-8000-4268b08e1ada"},
            {"attributes": {"data_source": {"type": "ColumnDataSource", "id": "data"}, "server_data_source": null, "doc": null, "nonselection_glyphspec": {"line_color": {"value": "#1f77b4"}, "line_width": {"units": "data", "field": "line_width"}, "angle_units": "deg", "x": {"units": "data", "field": "x"}, "type": "line", "y": {"units": "data", "field": "y"}, "line_alpha": {"units": "data", "value": 0.1}, "start_angle_units": "deg", "valign": null, "radius_units": "screen", "visible": null, "end_angle_units": "deg", "line_dash_offset": 0, "length_units": "screen", "line_cap": "butt", "line_dash": [], "margin": null, "line_join": "miter", "halign": null}, "xdata_range": null, "ydata_range": null, "glyphspec": {"line_color": {"value": "#0000FF"}, "line_alpha": {"units": "data", "value": 1.0}, "line_width": {"units": "data", "field": "line_width"}, "y": {"units": "data", "field": "y"}, "x": {"units": "data", "field": "x"}, "type": "line"}, "id": "2de55bd4-b714-4283-afd1-e443a04e906f"}, "type": "Glyph", "id": "2de55bd4-b714-4283-afd1-e443a04e906f"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "dimensions": ["width", "height"], "doc": null, "id": "06a57c95-fe07-4033-aee3-32e3d25afe19"}, "type": "PanTool", "id": "06a57c95-fe07-4033-aee3-32e3d25afe19"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "dimensions": ["width", "height"], "doc": null, "id": "b930820a-c2e7-427e-9bd4-501b709e346e"}, "type": "WheelZoomTool", "id": "b930820a-c2e7-427e-9bd4-501b709e346e"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "id": "d3013d8a-0524-4c87-a664-f78a06a3ff77", "doc": null}, "type": "ResetTool", "id": "d3013d8a-0524-4c87-a664-f78a06a3ff77"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "id": "77aa37cd-53c8-4d9d-998b-b9124f92c7ed", "doc": null}, "type": "PreviewSaveTool", "id": "77aa37cd-53c8-4d9d-998b-b9124f92c7ed"},
            {"attributes": {"outer_height": 600, "x_range": {"type": "DataRange1d", "id": "bbd5dd00-5564-4e65-9169-5c149e857686"}, "y_range": {"type": "DataRange1d", "id": "fc8abecf-9289-4f8d-8b60-ee9b834a46aa"}, "outer_width": 600, "renderers": [{"type": "LinearAxis", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560"}, {"type": "Grid", "id": "5a329fd3-154a-4ed5-a7a2-764384e3c1af"}, {"type": "LinearAxis", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e"}, {"type": "Grid", "id": "fac9970a-b9f6-443c-b412-83974d2528d3"}, {"type": "BoxSelection", "id": "c7af6b67-7298-4431-8000-4268b08e1ada"}, {"type": "Glyph", "id": "2de55bd4-b714-4283-afd1-e443a04e906f"}], "id": "line_example", "data_sources": [], "doc": null, "canvas_height": 600, "title": "Plot", "tools": [{"type": "PanTool", "id": "06a57c95-fe07-4033-aee3-32e3d25afe19"}, {"type": "WheelZoomTool", "id": "b930820a-c2e7-427e-9bd4-501b709e346e"}, {"type": "BoxZoomTool", "id": "91b7f168-6022-4019-98a9-31e6cd989671"}, {"type": "ResetTool", "id": "d3013d8a-0524-4c87-a664-f78a06a3ff77"}, {"type": "PreviewSaveTool", "id": "77aa37cd-53c8-4d9d-998b-b9124f92c7ed"}], "canvas_width": 600}, "type": "Plot", "id": "line_example"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "axis": {"type": "LinearAxis", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e"}, "id": "fac9970a-b9f6-443c-b412-83974d2528d3", "dimension": 1}, "type": "Grid", "id": "fac9970a-b9f6-443c-b412-83974d2528d3"},
            {"attributes": {"doc": null, "children": [{"type": "Plot", "id": "line_example"}], "id": "59ac3505-c899-4aeb-bc31-94f5a00e38a8"}, "type": "PlotContext", "id": "59ac3505-c899-4aeb-bc31-94f5a00e38a8"}];
            var modelid = "59ac3505-c899-4aeb-bc31-94f5a00e38a8";
            var modeltype = "PlotContext";
            var elementid = "CCF";
            console.log(modelid, modeltype, elementid);
            Bokeh.load_models(all_models);
            model = Bokeh.Collections(modeltype).get(modelid);
            view = new model.default_view({model: model, el: '#CCF'});
        });
    </script>
<script>
$(document).ready(function() {
    $( "#update" ).click(function() {
    data.attributes.data.x = [0,2,5]
        data.attributes.data.y = [0,2,5]
        view = new model.default_view({model: model, el: '#CCF'})
        });
});
</script>
</head>
<body>
    <div class="plotdiv" id="CCF">Plots</div>
    <div id="update" name='update'>

Click here

</body>

Le mardi 29 avril 2014 16:17:26 UTC+2, Bryan Van de ven a écrit :

Hi Thomas,

Right now Bokeh plots are only reactive from the updates from the server. Without the server, coupling a button press to “multiply all values by two” means that that data update has to happen purely in JavaScript. Perhaps we could think about exposing some kind of plug in system that allows events to be bound to arbitrary snippets of javascript, but there is no functionality for that currently.

Bryan

On Apr 29, 2014, at 6:35 AM, Thomas Lecocq [email protected] wrote:

Hi all,

I’m trying to make a minimal example of a line plot, that takes an external json content and plots it. I first would like just to load the json, not really have to rely on the bokeh-server or anything else… Once this is done, I want to be able to update the plot (say, click a button, multiply all elements from the data by 2, and update the view) … ?

Any hint ?

Thanks a lot,

Tom


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/6727a554-3420-4e33-b676-85a3ccef2273%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/f1f888f9-c084-4a31-a748-dda332b568e3%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Thomas,

Not an expert, but the spectrogram demo looks roughly like this (coffeescript):

  request_data: () ->
    $.ajax 'http://localhost:5000/data&#39;,
    type: 'GET'
    dataType: 'json'
    error: (jqXHR, textStatus, errorThrown) =>
      console.log("something failed")

    success: (data, textStatus, jqXHR) =>
      @do_stuff(data)

···

On Apr 30, 2014, at 4:12 AM, Thomas Lecocq <[email protected]> wrote:

Hi Bryan,

Digging into the JS code, I think I found some ways of updating the {x,y}_ranges on the view, which are not updated when I trigger the 'change' on the model.

Hope this gives new ideas :slight_smile: Next step: get x,y data from an $.ajax call :slight_smile:

Cheers,

Thom

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Animated - jsFiddle demo by bokeh</title>
  <script type='text/javascript' src='//code.jquery.com/jquery-2.0.2.js'></script>
  <link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css&quot;&gt;
  <link rel="stylesheet" type="text/css" href="http://cdn.pydata.org/bokeh-0.4.4.css&quot;&gt;
  <script type='text/javascript' src="bokeh-0.4.4.js"></script>
  
  <script type="text/coffeescript">
    x = [0,1,2,3]
    y = [1,2,5,6]
       
    color = ["#C6DBEF",]

    window.source = Bokeh.Collections('ColumnDataSource').create(
      data:
        color: color
        x: x
        y: y
    )

    line = {
      type: 'line'
      x: 'x'
      y: 'y'
      line_color: 'color'
      line_width: 2
      line_alpha: 1.0
    }

    options = {
      title: "CCF Update Demo"
      dims: [1000, 500]
      xrange: 'auto'
      yrange: 'auto'
      xaxes: "min"
      yaxes: "min"
      tools: "pan,wheel_zoom,box_zoom,reset,resize"
    }

    plot = Bokeh.Plotting.make_plot(line, window.source, options)
    Bokeh.Plotting.show(plot,'#CCF')

    #
    # Update the plot data on an interval
    #
    Array::max=->
      Math.max.apply(null, this)
     
    Array::min=->
      Math.min.apply(null, this)
      
    update = () ->
      data = window.source.get('data')
      tmp = (i * 1.1 for i in data['x'])
      data['x'] = tmp
      tmp = (Math.random() * 100 for i in data['y'])
      data['y'] = tmp
      
      window.source.set('data', data)
      window.source.trigger('change', source, {})
      
      console.debug(tmp.min())
      newrange = {}
      newrange['xr'] = {'start':data['x'].min(), 'end':data['x'].max()}
      newrange['yr'] = {'start':data['y'].min(), 'end':data['y'].max()}
      window.pview.update_range(newrange)
    
    setInterval(update, 1000)
  </script>
  <script type="text/javascript" src="coffeescript.js"></script>
</head>

<body>
<div id="CCF" name="CCF"></div>
</body>
</html>

Le mardi 29 avril 2014 17:44:54 UTC+2, Bryan Van de ven a écrit :
Thomas,

From BokehJS, you will need to trigger some change updates on the source by hand (would love to make this simpler, open to input). Check out the animated BokehJS jsfiddle:

        http://jsfiddle.net/bokeh/K8P4P/

Particularly the "update" function at the end:

update = () ->
  data = window.source.get('data')
  rmin = data["inner_radius"]
  tmp = [rmin[rmin.length-1]].concat(rmin.slice(0, -1))
  data["inner_radius"] = tmp
  rmax = data["outer_radius"]
  tmp = rmax.slice(1).concat([rmax[0]])
  data["outer_radius"] = tmp
  window.source.set('data', data)
  window.source.trigger('change', source, {})

The basic idea is that you need to grab a handle to the DataSource (in that example it's window.source but you will need to pull it out of your plot) and then use .set and .trigger to cause the redraw.

It suddenly occurs to me that this is a use-case I don't think had been considered: hybrid python+js dev. You could use python to easily generate the basic plot but then if you already have js pulling data in from somewhere, you could update the plot from js directly if the datasources, etc., are easily gotten ahold of. That seems pretty neat I will make an issue to explore this idea. Please let me know if you still need more info, or have ideas about this kind of use of Bokeh.

Thanks,

Bryan

On Apr 29, 2014, at 10:35 AM, Thomas Lecocq <[email protected]> wrote:

> Bryan,
>
> Thanks for your comment.
>
> I managed to expose almost enough of what I need... Could you just tell me how to trigger an update of the x_range,y_range, so the view fits the data added ?
>
> Thanks
>
> <!DOCTYPE html>
> <html lang="en">
> <head>
> <meta charset="utf-8">
> <title>line.py example</title>
> <link rel="stylesheet" href="http://cdn.pydata.org/bokeh-0.4.4.min.css&quot; type="text/css" />
> <script type="text/javascript" src="http://cdn.pydata.org/bokeh-0.4.4.min.js&quot;&gt;&lt;/script&gt;
> <script src="//code.jquery.com/jquery-1.10.2.js"></script>
> <script type="text/javascript">
> \(function\(\) \{ &gt; data = \{&quot;attributes&quot;: \{&quot;column\_names&quot;: \[&quot;x&quot;, &quot;y&quot;\], &quot;doc&quot;: null, &quot;selected&quot;: \[\], &quot;discrete\_ranges&quot;: \{\}, &quot;cont\_ranges&quot;: \{\}, &quot;data&quot;: \{&quot;y&quot;: \[0\.0, \], &quot;x&quot;: \[0\.0, \]\}, &quot;id&quot;: &quot;data&quot;\}, &quot;type&quot;: &quot;ColumnDataSource&quot;, &quot;id&quot;: &quot;data&quot;\}, &gt; all\_models = \[ &gt; data, &gt; &gt; \{&quot;attributes&quot;: \{&quot;sources&quot;: \[\{&quot;source&quot;: \{&quot;type&quot;: &quot;ColumnDataSource&quot;, &quot;id&quot;: &quot;data&quot;\}, &quot;columns&quot;: \[&quot;x&quot;\]\}\], &quot;id&quot;: &quot;bbd5dd00\-5564\-4e65\-9169\-5c149e857686&quot;, &quot;doc&quot;: null\}, &quot;type&quot;: &quot;DataRange1d&quot;, &quot;id&quot;: &quot;bbd5dd00\-5564\-4e65\-9169\-5c149e857686&quot;\}, &gt; &gt; \{&quot;attributes&quot;: \{&quot;sources&quot;: \[\{&quot;source&quot;: \{&quot;type&quot;: &quot;ColumnDataSource&quot;, &quot;id&quot;: &quot;data&quot;\}, &quot;columns&quot;: \[&quot;y&quot;\]\}\], &quot;id&quot;: &quot;fc8abecf\-9289\-4f8d\-8b60\-ee9b834a46aa&quot;, &quot;doc&quot;: null\}, &quot;type&quot;: &quot;DataRange1d&quot;, &quot;id&quot;: &quot;fc8abecf\-9289\-4f8d\-8b60\-ee9b834a46aa&quot;\}, &gt; &gt; \{&quot;attributes&quot;: \{&quot;doc&quot;: null, &quot;id&quot;: &quot;88360242\-94ef\-4839\-abb4\-d302553810d2&quot;\}, &quot;type&quot;: &quot;BasicTickFormatter&quot;, &quot;id&quot;: &quot;88360242\-94ef\-4839\-abb4\-d302553810d2&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;doc&quot;: null, &quot;id&quot;: &quot;8deaa0b1\-cab2\-47b3\-8674\-67f6ebfac56b&quot;\}, &quot;type&quot;: &quot;BasicTicker&quot;, &quot;id&quot;: &quot;8deaa0b1\-cab2\-47b3\-8674\-67f6ebfac56b&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;doc&quot;: null, &quot;bounds&quot;: &quot;auto&quot;, &quot;id&quot;: &quot;cca1aab2\-4f92\-40cd\-bc26\-cc6d71b18560&quot;, &quot;location&quot;: &quot;min&quot;, &quot;formatter&quot;: \{&quot;type&quot;: &quot;BasicTickFormatter&quot;, &quot;id&quot;: &quot;88360242\-94ef\-4839\-abb4\-d302553810d2&quot;\}, &quot;ticker&quot;: \{&quot;type&quot;: &quot;BasicTicker&quot;, &quot;id&quot;: &quot;8deaa0b1\-cab2\-47b3\-8674\-67f6ebfac56b&quot;\}, &quot;dimension&quot;: 0\}, &quot;type&quot;: &quot;LinearAxis&quot;, &quot;id&quot;: &quot;cca1aab2\-4f92\-40cd\-bc26\-cc6d71b18560&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;doc&quot;: null, &quot;axis&quot;: \{&quot;type&quot;: &quot;LinearAxis&quot;, &quot;id&quot;: &quot;cca1aab2\-4f92\-40cd\-bc26\-cc6d71b18560&quot;\}, &quot;id&quot;: &quot;5a329fd3\-154a\-4ed5\-a7a2\-764384e3c1af&quot;, &quot;dimension&quot;: 0\}, &quot;type&quot;: &quot;Grid&quot;, &quot;id&quot;: &quot;5a329fd3\-154a\-4ed5\-a7a2\-764384e3c1af&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;doc&quot;: null, &quot;id&quot;: &quot;7a9415cc\-8ed2\-459a\-b51a\-8bdb79ff282e&quot;\}, &quot;type&quot;: &quot;BasicTickFormatter&quot;, &quot;id&quot;: &quot;7a9415cc\-8ed2\-459a\-b51a\-8bdb79ff282e&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;doc&quot;: null, &quot;id&quot;: &quot;f83ecaba\-e25f\-42f9\-abfa\-f060af866bdf&quot;\}, &quot;type&quot;: &quot;BasicTicker&quot;, &quot;id&quot;: &quot;f83ecaba\-e25f\-42f9\-abfa\-f060af866bdf&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;doc&quot;: null, &quot;bounds&quot;: &quot;auto&quot;, &quot;id&quot;: &quot;85d7a783\-bc12\-42cc\-8d6f\-89ddb3d2458e&quot;, &quot;location&quot;: &quot;min&quot;, &quot;formatter&quot;: \{&quot;type&quot;: &quot;BasicTickFormatter&quot;, &quot;id&quot;: &quot;7a9415cc\-8ed2\-459a\-b51a\-8bdb79ff282e&quot;\}, &quot;ticker&quot;: \{&quot;type&quot;: &quot;BasicTicker&quot;, &quot;id&quot;: &quot;f83ecaba\-e25f\-42f9\-abfa\-f060af866bdf&quot;\}, &quot;dimension&quot;: 1\}, &quot;type&quot;: &quot;LinearAxis&quot;, &quot;id&quot;: &quot;85d7a783\-bc12\-42cc\-8d6f\-89ddb3d2458e&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;id&quot;: &quot;91b7f168\-6022\-4019\-98a9\-31e6cd989671&quot;, &quot;doc&quot;: null\}, &quot;type&quot;: &quot;BoxZoomTool&quot;, &quot;id&quot;: &quot;91b7f168\-6022\-4019\-98a9\-31e6cd989671&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;doc&quot;: null, &quot;tool&quot;: \{&quot;type&quot;: &quot;BoxZoomTool&quot;, &quot;id&quot;: &quot;91b7f168\-6022\-4019\-98a9\-31e6cd989671&quot;\}, &quot;id&quot;: &quot;c7af6b67\-7298\-4431\-8000\-4268b08e1ada&quot;\}, &quot;type&quot;: &quot;BoxSelection&quot;, &quot;id&quot;: &quot;c7af6b67\-7298\-4431\-8000\-4268b08e1ada&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;data\_source&quot;: \{&quot;type&quot;: &quot;ColumnDataSource&quot;, &quot;id&quot;: &quot;data&quot;\}, &quot;server\_data\_source&quot;: null, &quot;doc&quot;: null, &quot;nonselection\_glyphspec&quot;: \{&quot;line\_color&quot;: \{&quot;value&quot;: &quot;\#1f77b4&quot;\}, &quot;line\_width&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;field&quot;: &quot;line\_width&quot;\}, &quot;angle\_units&quot;: &quot;deg&quot;, &quot;x&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;field&quot;: &quot;x&quot;\}, &quot;type&quot;: &quot;line&quot;, &quot;y&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;field&quot;: &quot;y&quot;\}, &quot;line\_alpha&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;value&quot;: 0\.1\}, &quot;start\_angle\_units&quot;: &quot;deg&quot;, &quot;valign&quot;: null, &quot;radius\_units&quot;: &quot;screen&quot;, &quot;visible&quot;: null, &quot;end\_angle\_units&quot;: &quot;deg&quot;, &quot;line\_dash\_offset&quot;: 0, &quot;length\_units&quot;: &quot;screen&quot;, &quot;line\_cap&quot;: &quot;butt&quot;, &quot;line\_dash&quot;: \[\], &quot;margin&quot;: null, &quot;line\_join&quot;: &quot;miter&quot;, &quot;halign&quot;: null\}, &quot;xdata\_range&quot;: null, &quot;ydata\_range&quot;: null, &quot;glyphspec&quot;: \{&quot;line\_color&quot;: \{&quot;value&quot;: &quot;\#0000FF&quot;\}, &quot;line\_alpha&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;value&quot;: 1\.0\}, &quot;line\_width&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;field&quot;: &quot;line\_width&quot;\}, &quot;y&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;field&quot;: &quot;y&quot;\}, &quot;x&quot;: \{&quot;units&quot;: &quot;data&quot;, &quot;field&quot;: &quot;x&quot;\}, &quot;type&quot;: &quot;line&quot;\}, &quot;id&quot;: &quot;2de55bd4\-b714\-4283\-afd1\-e443a04e906f&quot;\}, &quot;type&quot;: &quot;Glyph&quot;, &quot;id&quot;: &quot;2de55bd4\-b714\-4283\-afd1\-e443a04e906f&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;dimensions&quot;: \[&quot;width&quot;, &quot;height&quot;\], &quot;doc&quot;: null, &quot;id&quot;: &quot;06a57c95\-fe07\-4033\-aee3\-32e3d25afe19&quot;\}, &quot;type&quot;: &quot;PanTool&quot;, &quot;id&quot;: &quot;06a57c95\-fe07\-4033\-aee3\-32e3d25afe19&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;dimensions&quot;: \[&quot;width&quot;, &quot;height&quot;\], &quot;doc&quot;: null, &quot;id&quot;: &quot;b930820a\-c2e7\-427e\-9bd4\-501b709e346e&quot;\}, &quot;type&quot;: &quot;WheelZoomTool&quot;, &quot;id&quot;: &quot;b930820a\-c2e7\-427e\-9bd4\-501b709e346e&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;id&quot;: &quot;d3013d8a\-0524\-4c87\-a664\-f78a06a3ff77&quot;, &quot;doc&quot;: null\}, &quot;type&quot;: &quot;ResetTool&quot;, &quot;id&quot;: &quot;d3013d8a\-0524\-4c87\-a664\-f78a06a3ff77&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;id&quot;: &quot;77aa37cd\-53c8\-4d9d\-998b\-b9124f92c7ed&quot;, &quot;doc&quot;: null\}, &quot;type&quot;: &quot;PreviewSaveTool&quot;, &quot;id&quot;: &quot;77aa37cd\-53c8\-4d9d\-998b\-b9124f92c7ed&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;outer\_height&quot;: 600, &quot;x\_range&quot;: \{&quot;type&quot;: &quot;DataRange1d&quot;, &quot;id&quot;: &quot;bbd5dd00\-5564\-4e65\-9169\-5c149e857686&quot;\}, &quot;y\_range&quot;: \{&quot;type&quot;: &quot;DataRange1d&quot;, &quot;id&quot;: &quot;fc8abecf\-9289\-4f8d\-8b60\-ee9b834a46aa&quot;\}, &quot;outer\_width&quot;: 600, &quot;renderers&quot;: \[\{&quot;type&quot;: &quot;LinearAxis&quot;, &quot;id&quot;: &quot;cca1aab2\-4f92\-40cd\-bc26\-cc6d71b18560&quot;\}, \{&quot;type&quot;: &quot;Grid&quot;, &quot;id&quot;: &quot;5a329fd3\-154a\-4ed5\-a7a2\-764384e3c1af&quot;\}, \{&quot;type&quot;: &quot;LinearAxis&quot;, &quot;id&quot;: &quot;85d7a783\-bc12\-42cc\-8d6f\-89ddb3d2458e&quot;\}, \{&quot;type&quot;: &quot;Grid&quot;, &quot;id&quot;: &quot;fac9970a\-b9f6\-443c\-b412\-83974d2528d3&quot;\}, \{&quot;type&quot;: &quot;BoxSelection&quot;, &quot;id&quot;: &quot;c7af6b67\-7298\-4431\-8000\-4268b08e1ada&quot;\}, \{&quot;type&quot;: &quot;Glyph&quot;, &quot;id&quot;: &quot;2de55bd4\-b714\-4283\-afd1\-e443a04e906f&quot;\}\], &quot;id&quot;: &quot;line\_example&quot;, &quot;data\_sources&quot;: \[\], &quot;doc&quot;: null, &quot;canvas\_height&quot;: 600, &quot;title&quot;: &quot;Plot&quot;, &quot;tools&quot;: \[\{&quot;type&quot;: &quot;PanTool&quot;, &quot;id&quot;: &quot;06a57c95\-fe07\-4033\-aee3\-32e3d25afe19&quot;\}, \{&quot;type&quot;: &quot;WheelZoomTool&quot;, &quot;id&quot;: &quot;b930820a\-c2e7\-427e\-9bd4\-501b709e346e&quot;\}, \{&quot;type&quot;: &quot;BoxZoomTool&quot;, &quot;id&quot;: &quot;91b7f168\-6022\-4019\-98a9\-31e6cd989671&quot;\}, \{&quot;type&quot;: &quot;ResetTool&quot;, &quot;id&quot;: &quot;d3013d8a\-0524\-4c87\-a664\-f78a06a3ff77&quot;\}, \{&quot;type&quot;: &quot;PreviewSaveTool&quot;, &quot;id&quot;: &quot;77aa37cd\-53c8\-4d9d\-998b\-b9124f92c7ed&quot;\}\], &quot;canvas\_width&quot;: 600\}, &quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;plot&quot;: \{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}, &quot;doc&quot;: null, &quot;axis&quot;: \{&quot;type&quot;: &quot;LinearAxis&quot;, &quot;id&quot;: &quot;85d7a783\-bc12\-42cc\-8d6f\-89ddb3d2458e&quot;\}, &quot;id&quot;: &quot;fac9970a\-b9f6\-443c\-b412\-83974d2528d3&quot;, &quot;dimension&quot;: 1\}, &quot;type&quot;: &quot;Grid&quot;, &quot;id&quot;: &quot;fac9970a\-b9f6\-443c\-b412\-83974d2528d3&quot;\}, &gt; \{&quot;attributes&quot;: \{&quot;doc&quot;: null, &quot;children&quot;: \[\{&quot;type&quot;: &quot;Plot&quot;, &quot;id&quot;: &quot;line\_example&quot;\}\], &quot;id&quot;: &quot;59ac3505\-c899\-4aeb\-bc31\-94f5a00e38a8&quot;\}, &quot;type&quot;: &quot;PlotContext&quot;, &quot;id&quot;: &quot;59ac3505\-c899\-4aeb\-bc31\-94f5a00e38a8&quot;\}\]; &gt; &gt; var modelid = &quot;59ac3505\-c899\-4aeb\-bc31\-94f5a00e38a8&quot;; &gt; var modeltype = &quot;PlotContext&quot;; &gt; var elementid = &quot;CCF&quot;; &gt; console\.log\(modelid, modeltype, elementid\); &gt; Bokeh\.load\_models\(all\_models\); &gt; model = Bokeh\.Collections\(modeltype\)\.get\(modelid\); &gt; view = new model\.default\_view\(\{model: model, el: &#39;\#CCF&#39;\}\); &gt; \}\); &gt; &lt;/script&gt; &gt; &lt;script&gt; &gt; (document).ready(function() {
> $( "#update" ).click(function() {
> data.attributes.data.x = [0,2,5]
> data.attributes.data.y = [0,2,5]
> view = new model.default_view({model: model, el: '#CCF'})
> });
> });
> </script>
> </head>
> <body>
> <div class="plotdiv" id="CCF">Plots</div>
> <div id="update" name='update'>
> Click here
> </div>
>
> </body>
> </html>
>
>
>
> Le mardi 29 avril 2014 16:17:26 UTC+2, Bryan Van de ven a écrit :
> Hi Thomas,
>
> Right now Bokeh plots are only reactive from the updates from the server. Without the server, coupling a button press to "multiply all values by two" means that that data update has to happen purely in JavaScript. Perhaps we could think about exposing some kind of plug in system that allows events to be bound to arbitrary snippets of javascript, but there is no functionality for that currently.
>
> Bryan
>
>
> On Apr 29, 2014, at 6:35 AM, Thomas Lecocq <[email protected]> wrote:
>
> > Hi all,
> >
> > I'm trying to make a minimal example of a line plot, that takes an external json content and plots it. I first would like just to load the json, not really have to rely on the bokeh-server or anything else... Once this is done, I want to be able to update the plot (say, click a button, multiply all elements from the data by 2, and update the view) ... ?
> >
> > Any hint ?
> >
> > Thanks a lot,
> >
> > Tom
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
> > To post to this group, send email to bo...@continuum.io.
> > To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/6727a554-3420-4e33-b676-85a3ccef2273%40continuum.io\.
> > For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/f1f888f9-c084-4a31-a748-dda332b568e3%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/b8fbc25a-601c-49a9-94fc-fbb062374a3c%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Bryan,

Yeha, somehow did the opposite, @update is in coffeescript, and the following is in javascript:

function get_CCF(callback, arg) {
    $.ajax({
        url:'/admin/all_results.json',
        type:'POST',
        dataType: 'json',
        contentTtupe: 'application/json',
        data: JSON.stringify(arg),
        success: callback
        });
    };

function updateplot() {
    var pair = $('#pair option:selected').text()
    var filter = $('#filter option:selected').val()
    var component = $('#component option:selected').text()
    var arg = {"pair": pair,"component": component,"filter":filter}
    console.debug(arg);
    get_CCF(update, arg);
    }

I’ll probably write some tutorial on that later soon, as it could definitively be useful for many. By the way, is there an API doc somewhere on the methods/calls/plots/etc available in Coffeescript ?

Thom

···

Le jeudi 1 mai 2014 16:48:48 UTC+2, Bryan Van de ven a écrit :

Thomas,

Not an expert, but the spectrogram demo looks roughly like this (coffeescript):

request_data: () →

$.ajax '[http://localhost:5000/data](http://localhost:5000/data)',

type: 'GET'

dataType: 'json'

error: (jqXHR, textStatus, errorThrown) =>

  console.log("something failed")



success: (data, textStatus, jqXHR) =>

  @do_stuff(data)

On Apr 30, 2014, at 4:12 AM, Thomas Lecocq [email protected] wrote:

Hi Bryan,

Digging into the JS code, I think I found some ways of updating the {x,y}_ranges on the view, which are not updated when I trigger the ‘change’ on the model.

Hope this gives new ideas :slight_smile: Next step: get x,y data from an $.ajax call :slight_smile:

Cheers,

Thom

Animated - jsFiddle demo by bokeh

Le mardi 29 avril 2014 17:44:54 UTC+2, Bryan Van de ven a écrit :

Thomas,

From BokehJS, you will need to trigger some change updates on the source by hand (would love to make this simpler, open to input). Check out the animated BokehJS jsfiddle:

    [http://jsfiddle.net/bokeh/K8P4P/](http://jsfiddle.net/bokeh/K8P4P/)

Particularly the “update” function at the end:

update = () →
data = window.source.get(‘data’)
rmin = data[“inner_radius”]
tmp = [rmin[rmin.length-1]].concat(rmin.slice(0, -1))
data[“inner_radius”] = tmp
rmax = data[“outer_radius”]
tmp = rmax.slice(1).concat([rmax[0]])
data[“outer_radius”] = tmp
window.source.set(‘data’, data)
window.source.trigger(‘change’, source, {})

The basic idea is that you need to grab a handle to the DataSource (in that example it’s window.source but you will need to pull it out of your plot) and then use .set and .trigger to cause the redraw.

It suddenly occurs to me that this is a use-case I don’t think had been considered: hybrid python+js dev. You could use python to easily generate the basic plot but then if you already have js pulling data in from somewhere, you could update the plot from js directly if the datasources, etc., are easily gotten ahold of. That seems pretty neat I will make an issue to explore this idea. Please let me know if you still need more info, or have ideas about this kind of use of Bokeh.

Thanks,

Bryan

On Apr 29, 2014, at 10:35 AM, Thomas Lecocq [email protected] wrote:

Bryan,

Thanks for your comment.

I managed to expose almost enough of what I need… Could you just tell me how to trigger an update of the x_range,y_range, so the view fits the data added ?

Thanks

line.py example $(function() { data = {"attributes": {"column_names": ["x", "y"], "doc": null, "selected": [], "discrete_ranges": {}, "cont_ranges": {}, "data": {"y": [0.0, ], "x": [0.0, ]}, "id": "data"}, "type": "ColumnDataSource", "id": "data"}, all_models = [ data,
            {"attributes": {"sources": [{"source": {"type": "ColumnDataSource", "id": "data"}, "columns": ["x"]}], "id": "bbd5dd00-5564-4e65-9169-5c149e857686", "doc": null}, "type": "DataRange1d", "id": "bbd5dd00-5564-4e65-9169-5c149e857686"},
           
            {"attributes": {"sources": [{"source": {"type": "ColumnDataSource", "id": "data"}, "columns": ["y"]}], "id": "fc8abecf-9289-4f8d-8b60-ee9b834a46aa", "doc": null}, "type": "DataRange1d", "id": "fc8abecf-9289-4f8d-8b60-ee9b834a46aa"},
           
            {"attributes": {"doc": null, "id": "88360242-94ef-4839-abb4-d302553810d2"}, "type": "BasicTickFormatter", "id": "88360242-94ef-4839-abb4-d302553810d2"},
            {"attributes": {"doc": null, "id": "8deaa0b1-cab2-47b3-8674-67f6ebfac56b"}, "type": "BasicTicker", "id": "8deaa0b1-cab2-47b3-8674-67f6ebfac56b"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "bounds": "auto", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560", "location": "min", "formatter": {"type": "BasicTickFormatter", "id": "88360242-94ef-4839-abb4-d302553810d2"}, "ticker": {"type": "BasicTicker", "id": "8deaa0b1-cab2-47b3-8674-67f6ebfac56b"}, "dimension": 0}, "type": "LinearAxis", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "axis": {"type": "LinearAxis", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560"}, "id": "5a329fd3-154a-4ed5-a7a2-764384e3c1af", "dimension": 0}, "type": "Grid", "id": "5a329fd3-154a-4ed5-a7a2-764384e3c1af"},
            {"attributes": {"doc": null, "id": "7a9415cc-8ed2-459a-b51a-8bdb79ff282e"}, "type": "BasicTickFormatter", "id": "7a9415cc-8ed2-459a-b51a-8bdb79ff282e"},
            {"attributes": {"doc": null, "id": "f83ecaba-e25f-42f9-abfa-f060af866bdf"}, "type": "BasicTicker", "id": "f83ecaba-e25f-42f9-abfa-f060af866bdf"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "bounds": "auto", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e", "location": "min", "formatter": {"type": "BasicTickFormatter", "id": "7a9415cc-8ed2-459a-b51a-8bdb79ff282e"}, "ticker": {"type": "BasicTicker", "id": "f83ecaba-e25f-42f9-abfa-f060af866bdf"}, "dimension": 1}, "type": "LinearAxis", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "id": "91b7f168-6022-4019-98a9-31e6cd989671", "doc": null}, "type": "BoxZoomTool", "id": "91b7f168-6022-4019-98a9-31e6cd989671"},
            {"attributes": {"doc": null, "tool": {"type": "BoxZoomTool", "id": "91b7f168-6022-4019-98a9-31e6cd989671"}, "id": "c7af6b67-7298-4431-8000-4268b08e1ada"}, "type": "BoxSelection", "id": "c7af6b67-7298-4431-8000-4268b08e1ada"},
            {"attributes": {"data_source": {"type": "ColumnDataSource", "id": "data"}, "server_data_source": null, "doc": null, "nonselection_glyphspec": {"line_color": {"value": "#1f77b4"}, "line_width": {"units": "data", "field": "line_width"}, "angle_units": "deg", "x": {"units": "data", "field": "x"}, "type": "line", "y": {"units": "data", "field": "y"}, "line_alpha": {"units": "data", "value": 0.1}, "start_angle_units": "deg", "valign": null, "radius_units": "screen", "visible": null, "end_angle_units": "deg", "line_dash_offset": 0, "length_units": "screen", "line_cap": "butt", "line_dash": [], "margin": null, "line_join": "miter", "halign": null}, "xdata_range": null, "ydata_range": null, "glyphspec": {"line_color": {"value": "#0000FF"}, "line_alpha": {"units": "data", "value": 1.0}, "line_width": {"units": "data", "field": "line_width"}, "y": {"units": "data", "field": "y"}, "x": {"units": "data", "field": "x"}, "type": "line"}, "id": "2de55bd4-b714-4283-afd1-e443a04e906f"}, "type": "Glyph", "id": "2de55bd4-b714-4283-afd1-e443a04e906f"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "dimensions": ["width", "height"], "doc": null, "id": "06a57c95-fe07-4033-aee3-32e3d25afe19"}, "type": "PanTool", "id": "06a57c95-fe07-4033-aee3-32e3d25afe19"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "dimensions": ["width", "height"], "doc": null, "id": "b930820a-c2e7-427e-9bd4-501b709e346e"}, "type": "WheelZoomTool", "id": "b930820a-c2e7-427e-9bd4-501b709e346e"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "id": "d3013d8a-0524-4c87-a664-f78a06a3ff77", "doc": null}, "type": "ResetTool", "id": "d3013d8a-0524-4c87-a664-f78a06a3ff77"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "id": "77aa37cd-53c8-4d9d-998b-b9124f92c7ed", "doc": null}, "type": "PreviewSaveTool", "id": "77aa37cd-53c8-4d9d-998b-b9124f92c7ed"},
            {"attributes": {"outer_height": 600, "x_range": {"type": "DataRange1d", "id": "bbd5dd00-5564-4e65-9169-5c149e857686"}, "y_range": {"type": "DataRange1d", "id": "fc8abecf-9289-4f8d-8b60-ee9b834a46aa"}, "outer_width": 600, "renderers": [{"type": "LinearAxis", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560"}, {"type": "Grid", "id": "5a329fd3-154a-4ed5-a7a2-764384e3c1af"}, {"type": "LinearAxis", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e"}, {"type": "Grid", "id": "fac9970a-b9f6-443c-b412-83974d2528d3"}, {"type": "BoxSelection", "id": "c7af6b67-7298-4431-8000-4268b08e1ada"}, {"type": "Glyph", "id": "2de55bd4-b714-4283-afd1-e443a04e906f"}], "id": "line_example", "data_sources": [], "doc": null, "canvas_height": 600, "title": "Plot", "tools": [{"type": "PanTool", "id": "06a57c95-fe07-4033-aee3-32e3d25afe19"}, {"type": "WheelZoomTool", "id": "b930820a-c2e7-427e-9bd4-501b709e346e"}, {"type": "BoxZoomTool", "id": "91b7f168-6022-4019-98a9-31e6cd989671"}, {"type": "ResetTool", "id": "d3013d8a-0524-4c87-a664-f78a06a3ff77"}, {"type": "PreviewSaveTool", "id": "77aa37cd-53c8-4d9d-998b-b9124f92c7ed"}], "canvas_width": 600}, "type": "Plot", "id": "line_example"},
            {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "axis": {"type": "LinearAxis", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e"}, "id": "fac9970a-b9f6-443c-b412-83974d2528d3", "dimension": 1}, "type": "Grid", "id": "fac9970a-b9f6-443c-b412-83974d2528d3"},
            {"attributes": {"doc": null, "children": [{"type": "Plot", "id": "line_example"}], "id": "59ac3505-c899-4aeb-bc31-94f5a00e38a8"}, "type": "PlotContext", "id": "59ac3505-c899-4aeb-bc31-94f5a00e38a8"}];
           
            var modelid = "59ac3505-c899-4aeb-bc31-94f5a00e38a8";
            var modeltype = "PlotContext";
            var elementid = "CCF";
            console.log(modelid, modeltype, elementid);
            Bokeh.load_models(all_models);
            model = Bokeh.Collections(modeltype).get(modelid);
            view = new model.default_view({model: model, el: '#CCF'});
        });
    </script>
<script>
$(document).ready(function() {
    $( "#update" ).click(function() {
    data.attributes.data.x = [0,2,5]
        data.attributes.data.y = [0,2,5]
        view = new model.default_view({model: model, el: '#CCF'})
        });
});
</script>
</head>
<body>
    <div class="plotdiv" id="CCF">Plots</div>
    <div id="update" name='update'>

Click here

</body>

Le mardi 29 avril 2014 16:17:26 UTC+2, Bryan Van de ven a écrit :
Hi Thomas,

Right now Bokeh plots are only reactive from the updates from the server. Without the server, coupling a button press to “multiply all values by two” means that that data update has to happen purely in JavaScript. Perhaps we could think about exposing some kind of plug in system that allows events to be bound to arbitrary snippets of javascript, but there is no functionality for that currently.

Bryan

On Apr 29, 2014, at 6:35 AM, Thomas Lecocq [email protected] wrote:

Hi all,

I’m trying to make a minimal example of a line plot, that takes an external json content and plots it. I first would like just to load the json, not really have to rely on the bokeh-server or anything else… Once this is done, I want to be able to update the plot (say, click a button, multiply all elements from the data by 2, and update the view) … ?

Any hint ?

Thanks a lot,

Tom


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/6727a554-3420-4e33-b676-85a3ccef2273%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/f1f888f9-c084-4a31-a748-dda332b568e3%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/b8fbc25a-601c-49a9-94fc-fbb062374a3c%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Thomas,

There is a reference for the glyph specs but there is not much of an API reference. On the other other, there is also not much of an API. :slight_smile: THer wis basically make_plot(...) and not much else at the high level. Apart from that there is just the object model, which is pretty well mirrored on the python side. Would love input on additional API to add, and would also be happy to include a BokehJS tutorial in the larger Bokeh tutorial at bokeh.pydata.org.

Thanks,

Bryan

···

On May 1, 2014, at 8:50 AM, Thomas Lecocq <[email protected]> wrote:

Bryan,

Yeha, somehow did the opposite, @update is in coffeescript, and the following is in javascript:

function get_CCF(callback, arg) {

    $.ajax({

        url:'/admin/all_results.json',

        type:'POST',

        dataType: 'json',

        contentTtupe: 'application/json',

        data: JSON.stringify(arg),

        success: callback

        });

    };

function updateplot() {

    var pair = $('#pair option:selected').text()

    var filter = $('#filter option:selected').val()

    var component = $('#component option:selected').text()

    var arg = {"pair": pair,"component": component,"filter":filter}

    console.debug(arg);

    get_CCF(update, arg);

    }

I'll probably write some tutorial on that later soon, as it could definitively be useful for many. By the way, is there an API doc somewhere on the methods/calls/plots/etc available in Coffeescript ?

Thom

Le jeudi 1 mai 2014 16:48:48 UTC+2, Bryan Van de ven a écrit :
Thomas,

Not an expert, but the spectrogram demo looks roughly like this (coffeescript):

  request_data: () ->
    $.ajax 'http://localhost:5000/data&#39;,
    type: 'GET'
    dataType: 'json'
    error: (jqXHR, textStatus, errorThrown) =>
      console.log("something failed")

    success: (data, textStatus, jqXHR) =>
      @do_stuff(data)

On Apr 30, 2014, at 4:12 AM, Thomas Lecocq <[email protected]> wrote:

> Hi Bryan,
>
> Digging into the JS code, I think I found some ways of updating the {x,y}_ranges on the view, which are not updated when I trigger the 'change' on the model.
>
> Hope this gives new ideas :slight_smile: Next step: get x,y data from an \.ajax call :\-\) &gt; &gt; Cheers, &gt; &gt; Thom &gt; &gt; &lt;\!DOCTYPE html&gt; &gt; &lt;html&gt; &gt; &lt;head&gt; &gt; &lt;meta http\-equiv=&quot;content\-type&quot; content=&quot;text/html; charset=UTF\-8&quot;&gt; &gt; &lt;title&gt;Animated \- jsFiddle demo by bokeh&lt;/title&gt; &gt; &lt;script type=&#39;text/javascript&#39; src=&#39;//code\.jquery\.com/jquery\-2\.0\.2\.js&#39;&gt;&lt;/script&gt; &gt; &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css&quot;&gt; &gt; &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://cdn.pydata.org/bokeh-0.4.4.css&quot;&gt; &gt; &lt;script type=&#39;text/javascript&#39; src=&quot;bokeh\-0\.4\.4\.js&quot;&gt;&lt;/script&gt; &gt; &gt; &lt;script type=&quot;text/coffeescript&quot;&gt; &gt; x = \[0,1,2,3\] &gt; y = \[1,2,5,6\] &gt; &gt; color = \[&quot;\#C6DBEF&quot;,\] &gt; &gt; window\.source = Bokeh\.Collections\(&#39;ColumnDataSource&#39;\)\.create\( &gt; data: &gt; color: color &gt; x: x &gt; y: y &gt; \) &gt; &gt; line = \{ &gt; type: &#39;line&#39; &gt; x: &#39;x&#39; &gt; y: &#39;y&#39; &gt; line\_color: &#39;color&#39; &gt; line\_width: 2 &gt; line\_alpha: 1\.0 &gt; \} &gt; &gt; options = \{ &gt; title: &quot;CCF Update Demo&quot; &gt; dims: \[1000, 500\] &gt; xrange: &#39;auto&#39; &gt; yrange: &#39;auto&#39; &gt; xaxes: &quot;min&quot; &gt; yaxes: &quot;min&quot; &gt; tools: &quot;pan,wheel\_zoom,box\_zoom,reset,resize&quot; &gt; \} &gt; &gt; plot = Bokeh\.Plotting\.make\_plot\(line, window\.source, options\) &gt; Bokeh\.Plotting\.show\(plot,&#39;\#CCF&#39;\) &gt; &gt; &gt; \# &gt; \# Update the plot data on an interval &gt; \# &gt; Array::max=\-&gt; &gt; Math\.max\.apply\(null, this\) &gt; &gt; Array::min=\-&gt; &gt; Math\.min\.apply\(null, this\) &gt; &gt; update = \(\) \-&gt; &gt; data = window\.source\.get\(&#39;data&#39;\) &gt; tmp = \(i \* 1\.1 for i in data\[&#39;x&#39;\]\) &gt; data\[&#39;x&#39;\] = tmp &gt; tmp = \(Math\.random\(\) \* 100 for i in data\[&#39;y&#39;\]\) &gt; data\[&#39;y&#39;\] = tmp &gt; &gt; window\.source\.set\(&#39;data&#39;, data\) &gt; window\.source\.trigger\(&#39;change&#39;, source, \{\}\) &gt; &gt; console\.debug\(tmp\.min\(\)\) &gt; newrange = \{\} &gt; newrange\[&#39;xr&#39;\] = \{&#39;start&#39;:data\[&#39;x&#39;\]\.min\(\), &#39;end&#39;:data\[&#39;x&#39;\]\.max\(\)\} &gt; newrange\[&#39;yr&#39;\] = \{&#39;start&#39;:data\[&#39;y&#39;\]\.min\(\), &#39;end&#39;:data\[&#39;y&#39;\]\.max\(\)\} &gt; window\.pview\.update\_range\(newrange\) &gt; &gt; setInterval\(update, 1000\) &gt; &lt;/script&gt; &gt; &lt;script type=&quot;text/javascript&quot; src=&quot;coffeescript\.js&quot;&gt;&lt;/script&gt; &gt; &lt;/head&gt; &gt; &gt; &lt;body&gt; &gt; &lt;div id=&quot;CCF&quot; name=&quot;CCF&quot;&gt;&lt;/div&gt; &gt; &lt;/body&gt; &gt; &lt;/html&gt; &gt; &gt; Le mardi 29 avril 2014 17:44:54 UTC\+2, Bryan Van de ven a écrit : &gt; Thomas, &gt; &gt; From BokehJS, you will need to trigger some change updates on the source by hand \(would love to make this simpler, open to input\)\. Check out the animated BokehJS jsfiddle: &gt; &gt; http://jsfiddle.net/bokeh/K8P4P/ &gt; &gt; Particularly the &quot;update&quot; function at the end: &gt; &gt; update = \(\) \-&gt; &gt; data = window\.source\.get\(&#39;data&#39;\) &gt; rmin = data\[&quot;inner\_radius&quot;\] &gt; tmp = \[rmin\[rmin\.length\-1\]\]\.concat\(rmin\.slice\(0, \-1\)\) &gt; data\[&quot;inner\_radius&quot;\] = tmp &gt; rmax = data\[&quot;outer\_radius&quot;\] &gt; tmp = rmax\.slice\(1\)\.concat\(\[rmax\[0\]\]\) &gt; data\[&quot;outer\_radius&quot;\] = tmp &gt; window\.source\.set\(&#39;data&#39;, data\) &gt; window\.source\.trigger\(&#39;change&#39;, source, \{\}\) &gt; &gt; The basic idea is that you need to grab a handle to the DataSource \(in that example it&#39;s window\.source but you will need to pull it out of your plot\) and then use \.set and \.trigger to cause the redraw\. &gt; &gt; It suddenly occurs to me that this is a use\-case I don&#39;t think had been considered: hybrid python\+js dev\. You could use python to easily generate the basic plot but then if you already have js pulling data in from somewhere, you could update the plot from js directly if the datasources, etc\., are easily gotten ahold of\. That seems pretty neat I will make an issue to explore this idea\. Please let me know if you still need more info, or have ideas about this kind of use of Bokeh\. &gt; &gt; Thanks, &gt; &gt; Bryan &gt; &gt; &gt; On Apr 29, 2014, at 10:35 AM, Thomas Lecocq &lt;thle\.\.\.@gmail\.com&gt; wrote: &gt; &gt; &gt; Bryan, &gt; &gt; &gt; &gt; Thanks for your comment\. &gt; &gt; &gt; &gt; I managed to expose almost enough of what I need\.\.\. Could you just tell me how to trigger an update of the x\_range,y\_range, so the view fits the data added ? &gt; &gt; &gt; &gt; Thanks &gt; &gt; &gt; &gt; &lt;\!DOCTYPE html&gt; &gt; &gt; &lt;html lang=&quot;en&quot;&gt; &gt; &gt; &lt;head&gt; &gt; &gt; &lt;meta charset=&quot;utf\-8&quot;&gt; &gt; &gt; &lt;title&gt;line\.py example&lt;/title&gt; &gt; &gt; &lt;link rel=&quot;stylesheet&quot; href=&quot;http://cdn.pydata.org/bokeh-0.4.4.min.css&quot; type=&quot;text/css&quot; /&gt; &gt; &gt; &lt;script type=&quot;text/javascript&quot; src=&quot;http://cdn.pydata.org/bokeh-0.4.4.min.js&quot;&gt;&lt;/script&gt; &gt; &gt; &lt;script src=&quot;//code\.jquery\.com/jquery\-1\.10\.2\.js&quot;&gt;&lt;/script&gt; &gt; &gt; &lt;script type=&quot;text/javascript&quot;&gt; &gt; &gt; (function() {
> > data = {"attributes": {"column_names": ["x", "y"], "doc": null, "selected": , "discrete_ranges": {}, "cont_ranges": {}, "data": {"y": [0.0, ], "x": [0.0, ]}, "id": "data"}, "type": "ColumnDataSource", "id": "data"},
> > all_models = [
> > data,
> >
> > {"attributes": {"sources": [{"source": {"type": "ColumnDataSource", "id": "data"}, "columns": ["x"]}], "id": "bbd5dd00-5564-4e65-9169-5c149e857686", "doc": null}, "type": "DataRange1d", "id": "bbd5dd00-5564-4e65-9169-5c149e857686"},
> >
> > {"attributes": {"sources": [{"source": {"type": "ColumnDataSource", "id": "data"}, "columns": ["y"]}], "id": "fc8abecf-9289-4f8d-8b60-ee9b834a46aa", "doc": null}, "type": "DataRange1d", "id": "fc8abecf-9289-4f8d-8b60-ee9b834a46aa"},
> >
> > {"attributes": {"doc": null, "id": "88360242-94ef-4839-abb4-d302553810d2"}, "type": "BasicTickFormatter", "id": "88360242-94ef-4839-abb4-d302553810d2"},
> > {"attributes": {"doc": null, "id": "8deaa0b1-cab2-47b3-8674-67f6ebfac56b"}, "type": "BasicTicker", "id": "8deaa0b1-cab2-47b3-8674-67f6ebfac56b"},
> > {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "bounds": "auto", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560", "location": "min", "formatter": {"type": "BasicTickFormatter", "id": "88360242-94ef-4839-abb4-d302553810d2"}, "ticker": {"type": "BasicTicker", "id": "8deaa0b1-cab2-47b3-8674-67f6ebfac56b"}, "dimension": 0}, "type": "LinearAxis", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560"},
> > {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "axis": {"type": "LinearAxis", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560"}, "id": "5a329fd3-154a-4ed5-a7a2-764384e3c1af", "dimension": 0}, "type": "Grid", "id": "5a329fd3-154a-4ed5-a7a2-764384e3c1af"},
> > {"attributes": {"doc": null, "id": "7a9415cc-8ed2-459a-b51a-8bdb79ff282e"}, "type": "BasicTickFormatter", "id": "7a9415cc-8ed2-459a-b51a-8bdb79ff282e"},
> > {"attributes": {"doc": null, "id": "f83ecaba-e25f-42f9-abfa-f060af866bdf"}, "type": "BasicTicker", "id": "f83ecaba-e25f-42f9-abfa-f060af866bdf"},
> > {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "bounds": "auto", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e", "location": "min", "formatter": {"type": "BasicTickFormatter", "id": "7a9415cc-8ed2-459a-b51a-8bdb79ff282e"}, "ticker": {"type": "BasicTicker", "id": "f83ecaba-e25f-42f9-abfa-f060af866bdf"}, "dimension": 1}, "type": "LinearAxis", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e"},
> > {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "id": "91b7f168-6022-4019-98a9-31e6cd989671", "doc": null}, "type": "BoxZoomTool", "id": "91b7f168-6022-4019-98a9-31e6cd989671"},
> > {"attributes": {"doc": null, "tool": {"type": "BoxZoomTool", "id": "91b7f168-6022-4019-98a9-31e6cd989671"}, "id": "c7af6b67-7298-4431-8000-4268b08e1ada"}, "type": "BoxSelection", "id": "c7af6b67-7298-4431-8000-4268b08e1ada"},
> > {"attributes": {"data_source": {"type": "ColumnDataSource", "id": "data"}, "server_data_source": null, "doc": null, "nonselection_glyphspec": {"line_color": {"value": "#1f77b4"}, "line_width": {"units": "data", "field": "line_width"}, "angle_units": "deg", "x": {"units": "data", "field": "x"}, "type": "line", "y": {"units": "data", "field": "y"}, "line_alpha": {"units": "data", "value": 0.1}, "start_angle_units": "deg", "valign": null, "radius_units": "screen", "visible": null, "end_angle_units": "deg", "line_dash_offset": 0, "length_units": "screen", "line_cap": "butt", "line_dash": , "margin": null, "line_join": "miter", "halign": null}, "xdata_range": null, "ydata_range": null, "glyphspec": {"line_color": {"value": "#0000FF"}, "line_alpha": {"units": "data", "value": 1.0}, "line_width": {"units": "data", "field": "line_width"}, "y": {"units": "data", "field": "y"}, "x": {"units": "data", "field": "x"}, "type": "line"}, "id": "2de55bd4-b714-4283-afd1-e443a04e906f"}, "type": "Glyph", "id": "2de55bd4-b714-4283-afd1-e443a04e906f"},
> > {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "dimensions": ["width", "height"], "doc": null, "id": "06a57c95-fe07-4033-aee3-32e3d25afe19"}, "type": "PanTool", "id": "06a57c95-fe07-4033-aee3-32e3d25afe19"},
> > {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "dimensions": ["width", "height"], "doc": null, "id": "b930820a-c2e7-427e-9bd4-501b709e346e"}, "type": "WheelZoomTool", "id": "b930820a-c2e7-427e-9bd4-501b709e346e"},
> > {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "id": "d3013d8a-0524-4c87-a664-f78a06a3ff77", "doc": null}, "type": "ResetTool", "id": "d3013d8a-0524-4c87-a664-f78a06a3ff77"},
> > {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "id": "77aa37cd-53c8-4d9d-998b-b9124f92c7ed", "doc": null}, "type": "PreviewSaveTool", "id": "77aa37cd-53c8-4d9d-998b-b9124f92c7ed"},
> > {"attributes": {"outer_height": 600, "x_range": {"type": "DataRange1d", "id": "bbd5dd00-5564-4e65-9169-5c149e857686"}, "y_range": {"type": "DataRange1d", "id": "fc8abecf-9289-4f8d-8b60-ee9b834a46aa"}, "outer_width": 600, "renderers": [{"type": "LinearAxis", "id": "cca1aab2-4f92-40cd-bc26-cc6d71b18560"}, {"type": "Grid", "id": "5a329fd3-154a-4ed5-a7a2-764384e3c1af"}, {"type": "LinearAxis", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e"}, {"type": "Grid", "id": "fac9970a-b9f6-443c-b412-83974d2528d3"}, {"type": "BoxSelection", "id": "c7af6b67-7298-4431-8000-4268b08e1ada"}, {"type": "Glyph", "id": "2de55bd4-b714-4283-afd1-e443a04e906f"}], "id": "line_example", "data_sources": , "doc": null, "canvas_height": 600, "title": "Plot", "tools": [{"type": "PanTool", "id": "06a57c95-fe07-4033-aee3-32e3d25afe19"}, {"type": "WheelZoomTool", "id": "b930820a-c2e7-427e-9bd4-501b709e346e"}, {"type": "BoxZoomTool", "id": "91b7f168-6022-4019-98a9-31e6cd989671"}, {"type": "ResetTool", "id": "d3013d8a-0524-4c87-a664-f78a06a3ff77"}, {"type": "PreviewSaveTool", "id": "77aa37cd-53c8-4d9d-998b-b9124f92c7ed"}], "canvas_width": 600}, "type": "Plot", "id": "line_example"},
> > {"attributes": {"plot": {"type": "Plot", "id": "line_example"}, "doc": null, "axis": {"type": "LinearAxis", "id": "85d7a783-bc12-42cc-8d6f-89ddb3d2458e"}, "id": "fac9970a-b9f6-443c-b412-83974d2528d3", "dimension": 1}, "type": "Grid", "id": "fac9970a-b9f6-443c-b412-83974d2528d3"},
> > {"attributes": {"doc": null, "children": [{"type": "Plot", "id": "line_example"}], "id": "59ac3505-c899-4aeb-bc31-94f5a00e38a8"}, "type": "PlotContext", "id": "59ac3505-c899-4aeb-bc31-94f5a00e38a8"}];
> >
> > var modelid = "59ac3505-c899-4aeb-bc31-94f5a00e38a8";
> > var modeltype = "PlotContext";
> > var elementid = "CCF";
> > console.log(modelid, modeltype, elementid);
> > Bokeh.load_models(all_models);
> > model = Bokeh.Collections(modeltype).get(modelid);
> > view = new model.default_view({model: model, el: '#CCF'});
> > });
> > </script>
> > <script>
> > \(document\)\.ready\(function\(\) \{ &gt; &gt; ( "#update" ).click(function() {
> > data.attributes.data.x = [0,2,5]
> > data.attributes.data.y = [0,2,5]
> > view = new model.default_view({model: model, el: '#CCF'})
> > });
> > });
> > </script>
> > </head>
> > <body>
> > <div class="plotdiv" id="CCF">Plots</div>
> > <div id="update" name='update'>
> > Click here
> > </div>
> >
> > </body>
> > </html>
> >
> >
> >
> > Le mardi 29 avril 2014 16:17:26 UTC+2, Bryan Van de ven a écrit :
> > Hi Thomas,
> >
> > Right now Bokeh plots are only reactive from the updates from the server. Without the server, coupling a button press to "multiply all values by two" means that that data update has to happen purely in JavaScript. Perhaps we could think about exposing some kind of plug in system that allows events to be bound to arbitrary snippets of javascript, but there is no functionality for that currently.
> >
> > Bryan
> >
> >
> > On Apr 29, 2014, at 6:35 AM, Thomas Lecocq <[email protected]> wrote:
> >
> > > Hi all,
> > >
> > > I'm trying to make a minimal example of a line plot, that takes an external json content and plots it. I first would like just to load the json, not really have to rely on the bokeh-server or anything else... Once this is done, I want to be able to update the plot (say, click a button, multiply all elements from the data by 2, and update the view) ... ?
> > >
> > > Any hint ?
> > >
> > > Thanks a lot,
> > >
> > > Tom
> > >
> > > --
> > > You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> > > To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
> > > To post to this group, send email to bo...@continuum.io.
> > > To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/6727a554-3420-4e33-b676-85a3ccef2273%40continuum.io\.
> > > For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
> > To post to this group, send email to bo...@continuum.io.
> > To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/f1f888f9-c084-4a31-a748-dda332b568e3%40continuum.io\.
> > For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/b8fbc25a-601c-49a9-94fc-fbb062374a3c%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/35842ee3-5445-4bf1-b723-e85cc6097be0%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.