specifying name of saved plot image file

Hi,

I’m wondering if there’s a way to specify the default name of the file that the plot image is saved to when you click on the “save” button for a plot. Any help on this would be appreciated.

Thanks,

Jon

Hi,

Unfortunately not, browsers all behave completely differently with regards to opening a link to the image from the canvas. Some open a tab which can be manually “saved as”, some prompt for download with a dialog, some just immediately download the file. We don’t have any control over these differences. If it would work for your use case to save things programmatically instead of manually with a tool on the plot, I would recommend looking at the functions in bokeh.export.

Thanks,

Bryan

···

On Jul 3, 2018, at 09:59, Jonathan Slavin [email protected] wrote:

Hi,

I’m wondering if there’s a way to specify the default name of the file that the plot image is saved to when you click on the “save” button for a plot. Any help on this would be appreciated.

Thanks,

Jon

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/69e9e544-4a42-4faa-8636-d8150f553ab2%40continuum.io.

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

Thanks for the response, Bryan.

My use case is a user looking over the plots in the pre-generated html page. If the person wants to save a plot (one of several on the page) then they would click the save button on the plot to save it to a png file. So I don’t know in advance if the person wants to save the plot and the saving happens later after my script has generated the html file. I don’t suppose it’d be possible to change contents of that link in the canvas…

Somehow the name of the png is set to bokeh_plot.png by default. Any idea where that name is set? I’m wondering if that could be changed somehow.

Thanks,

Jon

···

On Tuesday, July 3, 2018 at 1:20:46 PM UTC-4, Bryan Van de ven wrote:

Hi,

Unfortunately not, browsers all behave completely differently with regards to opening a link to the image from the canvas. Some open a tab which can be manually “saved as”, some prompt for download with a dialog, some just immediately download the file. We don’t have any control over these differences. If it would work for your use case to save things programmatically instead of manually with a tool on the plot, I would recommend looking at the functions in bokeh.export.

Thanks,

Bryan

On Jul 3, 2018, at 09:59, Jonathan Slavin [email protected] wrote:

Hi,

I’m wondering if there’s a way to specify the default name of the file that the plot image is saved to when you click on the “save” button for a plot. Any help on this would be appreciated.

Thanks,

Jon

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/69e9e544-4a42-4faa-8636-d8150f553ab2%40continuum.io.

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

Hi,

Your browser is choosing that name, and it’s probably a different name on a different browser (or none at all, some open tabs instead, as I mentioned). This is what Bokeh does:

        const canvas = this.canvas_view.get_canvas_element() as HTMLCanvasElement
if (canvas.msToBlob != null) {
const blob = canvas.msToBlob()
window.navigator.msSaveBlob(blob, name)
} else {
const link = document.createElement('a')
link.href = canvas.toDataURL('image/png')
link.download = name + ".png"
link.target = "_blank"
link.dispatchEvent(new MouseEvent('click'))
[https://github.com/bokeh/bokeh/blob/master/bokehjs/src/lib/models/plots/plot_canvas.ts#L932-L941](https://github.com/bokeh/bokeh/blob/master/bokehjs/src/lib/models/plots/plot_canvas.ts#L932-L941)

And in fact, the “name” variable above is actually hard coded to “bokeh_plot”, not “default”:

 this.plot_view.save("bokeh_plot")

https://github.com/bokeh/bokeh/blob/master/bokehjs/src/lib/models/tools/actions/save_tool.ts#L7

Ideally, the code would always open a new tab with the image, and allow users to “save as” using whatever name they would like. Or as a fallback, maybe we could expect browser to at least save using the name we provide (“bokeh_plot”) so that we could expose that as a configurable option. But the reality is that HTML/JS/CSS are a nightmare, and browsers often do whatever they want. Some of them, instead of opening a tab as the code would suggest, automatically save the target instead, evidently as “default”, regardless of what is supposed to happen.

If you or someone you know have better or different ideas, I’d be happy to collaborate. But I have not been able to find a solution to this so someone else will have to take the lead.

Thanks,

Bryan

···

On Jul 3, 2018, at 10:34, Jonathan Slavin [email protected] wrote:

Thanks for the response, Bryan.

My use case is a user looking over the plots in the pre-generated html page. If the person wants to save a plot (one of several on the page) then they would click the save button on the plot to save it to a png file. So I don’t know in advance if the person wants to save the plot and the saving happens later after my script has generated the html file. I don’t suppose it’d be possible to change contents of that link in the canvas…

Somehow the name of the png is set to bokeh_plot.png by default. Any idea where that name is set? I’m wondering if that could be changed somehow.

Thanks,

Jon

On Tuesday, July 3, 2018 at 1:20:46 PM UTC-4, Bryan Van de ven wrote:

Hi,

Unfortunately not, browsers all behave completely differently with regards to opening a link to the image from the canvas. Some open a tab which can be manually “saved as”, some prompt for download with a dialog, some just immediately download the file. We don’t have any control over these differences. If it would work for your use case to save things programmatically instead of manually with a tool on the plot, I would recommend looking at the functions in bokeh.export.

Thanks,

Bryan

On Jul 3, 2018, at 09:59, Jonathan Slavin [email protected] wrote:

Hi,

I’m wondering if there’s a way to specify the default name of the file that the plot image is saved to when you click on the “save” button for a plot. Any help on this would be appreciated.

Thanks,

Jon

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/69e9e544-4a42-4faa-8636-d8150f553ab2%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/e6f1e230-ca2e-4166-b5b3-9306d2a8a73a%40continuum.io.

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

Okay, that clears things up. By the way, I think you may have misread what I wrote about the default file name. My browser (chrome) does indeed use “bokeh_plot.png” as the default name, as expected.

Jon

···

On Tuesday, July 3, 2018 at 1:56:22 PM UTC-4, Bryan Van de ven wrote:

Hi,

Your browser is choosing that name, and it’s probably a different name on a different browser (or none at all, some open tabs instead, as I mentioned). This is what Bokeh does:

const canvas = this.canvas_view.get_canvas_        element() as HTMLCanvasElement
if (canvas.msToBlob != null) {
const blob = canvas.msToBlob()
window.navigator.msSaveBlob(        blob, name)
} else {
const link = document.createElement('a')
link.href = canvas.toDataURL('image/png')
link.download = name + ".png"
link.target = "_blank"
link.dispatchEvent(new MouseEvent('click'))
[https://github.com/bokeh/bokeh/blob/master/bokehjs/src/lib/models/plots/plot_canvas.ts#L932-L941](https://github.com/bokeh/bokeh/blob/master/bokehjs/src/lib/models/plots/plot_canvas.ts#L932-L941)

And in fact, the “name” variable above is actually hard coded to “bokeh_plot”, not “default”:

this.plot_view.save(“bokeh_plot”)

https://github.com/bokeh/bokeh/blob/master/bokehjs/src/lib/models/tools/actions/save_tool.ts#L7

Ideally, the code would always open a new tab with the image, and allow users to “save as” using whatever name they would like. Or as a fallback, maybe we could expect browser to at least save using the name we provide (“bokeh_plot”) so that we could expose that as a configurable option. But the reality is that HTML/JS/CSS are a nightmare, and browsers often do whatever they want. Some of them, instead of opening a tab as the code would suggest, automatically save the target instead, evidently as “default”, regardless of what is supposed to happen.

If you or someone you know have better or different ideas, I’d be happy to collaborate. But I have not been able to find a solution to this so someone else will have to take the lead.

Thanks,

Bryan

On Jul 3, 2018, at 10:34, Jonathan Slavin [email protected] wrote:

Thanks for the response, Bryan.

My use case is a user looking over the plots in the pre-generated html page. If the person wants to save a plot (one of several on the page) then they would click the save button on the plot to save it to a png file. So I don’t know in advance if the person wants to save the plot and the saving happens later after my script has generated the html file. I don’t suppose it’d be possible to change contents of that link in the canvas…

Somehow the name of the png is set to bokeh_plot.png by default. Any idea where that name is set? I’m wondering if that could be changed somehow.

Thanks,

Jon

On Tuesday, July 3, 2018 at 1:20:46 PM UTC-4, Bryan Van de ven wrote:

Hi,

Unfortunately not, browsers all behave completely differently with regards to opening a link to the image from the canvas. Some open a tab which can be manually “saved as”, some prompt for download with a dialog, some just immediately download the file. We don’t have any control over these differences. If it would work for your use case to save things programmatically instead of manually with a tool on the plot, I would recommend looking at the functions in bokeh.export.

Thanks,

Bryan

On Jul 3, 2018, at 09:59, Jonathan Slavin [email protected] wrote:

Hi,

I’m wondering if there’s a way to specify the default name of the file that the plot image is saved to when you click on the “save” button for a plot. Any help on this would be appreciated.

Thanks,

Jon

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/69e9e544-4a42-4faa-8636-d8150f553ab2%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/e6f1e230-ca2e-4166-b5b3-9306d2a8a73a%40continuum.io.

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

Hi,

I’d be happy to have the name exposed as a configurable property on the SaveTool model. It would only a be a few lines of code and make a good PR for a new contributor. I’d be happy to help anyone work that up. It would need some loud warnings in the property help string to note that not all browsers will respect the value (e.g. some open a tab and won’t save automatically) and that it is provided as-is for cases where it happens to work.

Thanks,

Bryan

···

On Jul 3, 2018, at 11:07, Jonathan Slavin [email protected] wrote:

Okay, that clears things up. By the way, I think you may have misread what I wrote about the default file name. My browser (chrome) does indeed use “bokeh_plot.png” as the default name, as expected.

Jon

On Tuesday, July 3, 2018 at 1:56:22 PM UTC-4, Bryan Van de ven wrote:

Hi,

Your browser is choosing that name, and it’s probably a different name on a different browser (or none at all, some open tabs instead, as I mentioned). This is what Bokeh does:

const canvas = this.canvas_view.get_canvas_        element() as HTMLCanvasElement
if (canvas.msToBlob != null) {
const blob = canvas.msToBlob()
window.navigator.msSaveBlob(        blob, name)
} else {
const link = document.createElement('a')
link.href = canvas.toDataURL('image/png')
link.download = name + ".png"
link.target = "_blank"
link.dispatchEvent(new MouseEvent('click'))
[https://github.com/bokeh/bokeh/blob/master/bokehjs/src/lib/models/plots/plot_canvas.ts#L932-L941](https://github.com/bokeh/bokeh/blob/master/bokehjs/src/lib/models/plots/plot_canvas.ts#L932-L941)

And in fact, the “name” variable above is actually hard coded to “bokeh_plot”, not “default”:

this.plot_view.save("bokeh_plot")

https://github.com/bokeh/bokeh/blob/master/bokehjs/src/lib/models/tools/actions/save_tool.ts#L7

Ideally, the code would always open a new tab with the image, and allow users to “save as” using whatever name they would like. Or as a fallback, maybe we could expect browser to at least save using the name we provide (“bokeh_plot”) so that we could expose that as a configurable option. But the reality is that HTML/JS/CSS are a nightmare, and browsers often do whatever they want. Some of them, instead of opening a tab as the code would suggest, automatically save the target instead, evidently as “default”, regardless of what is supposed to happen.

If you or someone you know have better or different ideas, I’d be happy to collaborate. But I have not been able to find a solution to this so someone else will have to take the lead.

Thanks,

Bryan

On Jul 3, 2018, at 10:34, Jonathan Slavin <jsl…@cfa.harvard.edu> wrote:

Thanks for the response, Bryan.

My use case is a user looking over the plots in the pre-generated html page. If the person wants to save a plot (one of several on the page) then they would click the save button on the plot to save it to a png file. So I don’t know in advance if the person wants to save the plot and the saving happens later after my script has generated the html file. I don’t suppose it’d be possible to change contents of that link in the canvas…

Somehow the name of the png is set to bokeh_plot.png by default. Any idea where that name is set? I’m wondering if that could be changed somehow.

Thanks,

Jon

On Tuesday, July 3, 2018 at 1:20:46 PM UTC-4, Bryan Van de ven wrote:

Hi,

Unfortunately not, browsers all behave completely differently with regards to opening a link to the image from the canvas. Some open a tab which can be manually “saved as”, some prompt for download with a dialog, some just immediately download the file. We don’t have any control over these differences. If it would work for your use case to save things programmatically instead of manually with a tool on the plot, I would recommend looking at the functions in bokeh.export.

Thanks,

Bryan

On Jul 3, 2018, at 09:59, Jonathan Slavin <jsl…@cfa.harvard.edu> wrote:

Hi,

I’m wondering if there’s a way to specify the default name of the file that the plot image is saved to when you click on the “save” button for a plot. Any help on this would be appreciated.

Thanks,

Jon


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/69e9e544-4a42-4faa-8636-d8150f553ab2%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/e6f1e230-ca2e-4166-b5b3-9306d2a8a73a%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/f0f88606-b200-4cc3-a897-cb456fe6c522%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

I have a version of savetool working with custom names I detailed here on stackoverflow. I keep a text box at the bottom of the page where the on_change for that updates the savetool configuration to change the default name for the image. However probably won’t actually help if you’re not using the bokeh server.

Jack

I just posted an updated version of a custom save tool on the same thread. It works with more recent versions of Bokeh (tested with 2.3.2).

Here I started from the SaveTool code. I had to scrap the parts related to the ‘copy’ function because for some reason ClipBoardItem could not be found in this context.

Working on this I figured it would indeed be easy to modify the original SaveTool so that it exposes a save_name property that can be modified in Python.

I personally think it would be useful to users (see typical use case described above). If that’s still of interest I could make a PR for this, provided I can navigate the challenges related to the fact that the changes mostly concern bokehjs.

I’d be interested in a PR if it can be demonstrated to work on all common OS and browser combinations. The major problem with a any feature that doesn’t or can’t work on some browsers is that the net result is an increased support burden for the core team when people complain that it is not working for them (even if not-working on a given browser is expected and documented)