How to Download a DataTable as a .csv in a bokeh_server app

Jordan,

Ah, I completely misunderstood your question. So, to do this will require some JavaScript. It's possible this could go in a CustomJS callback for a button, maybe? Here are some links that might prove useful:

  pandas - Download CSV from an iPython Notebook - Stack Overflow

  How to export JavaScript array info to csv (on client side)? - Stack Overflow

Thanks,

Bryan

···

On Apr 19, 2016, at 3:19 PM, Jordan Bramble <[email protected]> wrote:

right. That part is quite simple. The difficult part is getting it to download in a web browser, instead of just save to the server at the call of df.to_csv()

On Tue, Apr 19, 2016 at 4:08 PM, Bryan Van de Ven <[email protected]> wrote:
Hi Jordan,

The data table has a data source property, which is a ColumnDataSource. This is turn has a .data property, is just a python dict of named columns. I would imagine it should be straightforward to pass this dict to pandas to get a Dataframe which can then be saved or exported in nay of the ways Pandas supports. Is that the sort of guidance you are looking for?

Bryan

> On Apr 19, 2016, at 2:15 PM, Jordan Bramble <[email protected]> wrote:
>
> Can anyone offer an example of this?
>
> On Monday, April 18, 2016 at 2:33:25 PM UTC-4, Jordan Bramble wrote:
> Hi I have a bokeh server app. running in 0.11.1. One component of my app is a DataTable. I want to save the data in this table as a .csv, so that someone can click a button and download the .csv through their browser. Here is a snipped of what I have done so far.
>
> def download():
> export = pd.DataFrame(source6.data)
> buffer = io.StringIO()
> export.to_csv(buffer, index=False, encoding='utf-8')
>
> #save(vform(data_table))
>
> controls = [store_name, inventory, min_year, max_year, min_month, max_month, button]
> for control in controls[:-1]:
> control.on_change('value', update)
> controls[-1].on_click(download)
>
>
> the download function, converts the data souce tied to the dataTable to a dataframe. then writes it to the buffer. from their I have no idea how to download it in the browser.
> I have a button defined in the app. When this button is clicked the download function is called. but of course that function is not complete. So I am hoping someone can help me download it.
>
> I tried to use the bokeh method save(), but when running on the server, the save function is ignored.
>
> Additionally, I have another issue where everytime I click a button the page is reloaded and a new session is created. This is a bug I believe, that has supposedly been fixed in a PR.
>
> Thanks for the help. Attached are pictures of my app.
>
>
>
>
> --
> 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/ddc3bee8-afbd-474a-a5c1-5a52cf2a3f18%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/678EFD14-1A46-460A-AB91-8CC78FE12EB5%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/CAB%3DGhauh0sJi0zzDgR3b02LjXfj1Q42-ebVw0x29NUTLY%3D1NUg%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.