# Extract selected data in Bokeh to text file and other questions

**URL:** <https://discourse.bokeh.org/t/extract-selected-data-in-bokeh-to-text-file-and-other-questions/2444>\
**Category:** Community Support\
**Created:** [September 9, 2017, 10:53pm UTC](https://discourse.bokeh.org/t/extract-selected-data-in-bokeh-to-text-file-and-other-questions/2444 "2017-09-09T22:53:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jesse\_Hutchinson](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/j/779978/32.png) [@Jesse\_Hutchinson](https://discourse.bokeh.org/u/Jesse_Hutchinson)\
**Post date:** [September 9, 2017, 10:53pm UTC](https://discourse.bokeh.org/t/extract-selected-data-in-bokeh-to-text-file-and-other-questions/2444/1 "2017-09-09T22:53:25Z")

</div>

I am currently working on a Bokeh script that will display an earthquake catalogue on a map. So far, I have had little trouble, but I have stumbled upon a couple questions.

1. I came upon this stackoverflow Q&A: [Get selected data contained within box select tool in Bokeh](https://stackoverflow.com/questions/34164587/get-selected-data-contained-within-box-select-tool-in-bokeh), which was very helpful in learning how to use CutsomJS to take the selected data and output it. I have, however encountered a bit of oddness. The script only seems to work properly for me in the Jupyter notebook. The CustomJS portion reads as follows:

```auto
source.callback = CustomJS(args=dict(p=p), code= """
var inds = cb_obj.get('selected')['1d'].indices;
var d1 = cb_obj.get('data');
console.log(d1)
var kernel = IPython.notebook.kernel;
IPython.notebook.kernel.execute("inds = " + inds);

```

If I try running it through and html window, the following command has no output:

```auto
subset = zip([source.data['xvals'][i] for i in inds],
    [source.data['yvals'][i] for i in inds])
subset_array = np.array(subset)
outfile = 'Scripts/subset.xy'
fo = open(outfile,'w')
for i in range(len(subset_array)):
    print(subset_array[i,0],subset_array[i,1],file=fo)
fo.close()

```

I could use some advice on how to get the selected data to output to a variable, and ultimately a text file when using html, as opposed to the Jupyter notebook.

1. I have been trying to create a legend for my plot. The earthquakes are indicated by circles (so it is a circle plot), and the circles vary in size based on their magnitude and in colour based on their depth, which I have gotten to work. What I would like to do is show circles of different sizes in the legend, each reflecting different magnitudes (Mag 1, Mag 2, Mag 3, etc.). Here’s the command I use for plotting the data:

```auto
p.circle("xvals", "yvals",source=source, size="radius", fill_color=transform("depth", mapper),legend = 'Magnitude')

```

I’ve tried messing around with the legend commands, but it’s all a bit difficult for me to grok, even though I feel like this should be a pretty simple thing to do.

I am utilizing the latest version of Bokeh (0.12.7) and Python 2.7.12. Thanks for any help, and I appreciate the time!

---

<div class="post-metadata">

**Author:** ![system](https://discourse-uploads.bokeh.org/original/2X/1/14eb24f9e10e4e9b78e3f10f66c04ffa96446e5a.svg) [@system](https://discourse.bokeh.org/u/system)\
**Post date:** [July 21, 2021, 9:12pm UTC](https://discourse.bokeh.org/t/extract-selected-data-in-bokeh-to-text-file-and-other-questions/2444/2 "2021-07-21T21:12:52Z")

</div>


