I'm trying to edit the modeBarButtons of a plotly graph such that the 'save and edit plot in cloud' function becomes disabled. At first this didn't seem possible in Python. But this post pointed out a workaround for Python, by casting the object to HTML and editing the HTML code.
Unfortunately, the 'save and edit plot in cloud' functionality remains when I try the example code below:
import numpy as np
from IPython.display import display, HTML
from plotly.offline import download_plotlyjs, init_notebook_mode, plot
import plotly
import plotly.graph_objs as go
plotly.offline.init_notebook_mode()
# create sin data to plot
x = np.arange(0.0, 100.0, 0.1)
y = np.sin(x)
# create plot data, edit and plot
trace0 = go.Scatter(x=x,y=y, name="Sin")
HTML_code = plot([trace0], show_link=False, auto_open=False, output_type='div')
HTML_code = HTML_code.replace('modeBarButtonsToRemove:[]',
'modeBarButtonsToRemove:["sendDataToCloud"]')
display(HTML(HTML_code))
[Edit] Write to file: The button is successfully removed when the edited HTML is written to file and opened in a browser.
Reloading the edited file into my notebook was unsuccessful:
from IPython.display import display, HTML
with open('./temp-plot.html', 'r') as file :
tempHTML = file.read()
display(HTML(tempHTML))
Javascript error adding output!
ReferenceError: Plotly is not defined See your browser Javascript console for more details.
Using output_type='div' instead of output_type='file' (my preferred approach due to write restrictions for the final product):
The notebook seems to 'reload' plotlys' standard configuration and only insert the data from the HTML, leaving the edited JavaScript unused.
Any suggestions?
Regards, Koen