2

My dataframe looks something like this(only a very small subset since the entire data is quite large):

data = [{'id': {0: 70.0, 1: 77.0,2: 78.0,3: 83.0,4: 84.0,5: 85.0,6: 90.0,7: 96.0,8: 124.0,9: 125.0},
 'commits': {0: 32, 1: 32, 2: 32,3: 32,4: 37,5: 37,6: 10,7: 10,8: 10, 9: 10},
 'info_title': {0: 'SQAaaS API',1: 'SQAaaS API',2: 'SQAaaS API',3: 'SQAaaS API',4: 'Registry of Open Community Challenge API',5: 'Challenge API', 6: 'Onfido API',7: 'Onfido API', 8: 'Onfido API',9: 'Onfido API'},
 'API Age': {0: 74, 1: 74, 2: 74, 3: 74, 4: 22, 5: 22, 6: 124, 7: 124,8: 124, 9: 124},
 'Total_Versions': {0: 1, 1: 1, 2: 1, 3: 1,4: 1,5: 1, 6: 3, 7: 3,8: 3, 9: 3}} ]

I have a plotly graph which I put in a dash app, which has hover over every bubble, somehow it is visible in VScode jupyter notebook and in the browser, but when I try to play the presentation in Spectacle editor, it does not give me the option of hover.

The code for my graph is here:

fig = px.scatter(final_api, x="API Age", y="Total_Versions", color="commits", hover_name="info_title", height=900, width=1000, size='Total_Versions', size_max=30,color_continuous_scale=px.colors.sequential.Inferno)
fig.update_layout(
    template='ggplot2',
    yaxis_title=" Total number of versions",
    xaxis_title="Age of the API (in days)",
    yaxis_range=[0, 180],
    hoverlabel=dict(font_size=16, font_family="PT Sans"),font=dict(size=20, family='PT Sans'), paper_bgcolor='rgba(233,233,233,100)'
)
fig.update_xaxes(showline=True, linewidth=1, linecolor='black', mirror=True)
fig.update_yaxes(showline=True, linewidth=1, linecolor='black', mirror=True)
fig.show()


import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()
app.layout = html.Div([
    dcc.Graph(figure=fig)
])

app.run_server(debug=True, use_reloader=True)

Can anyone tell me where am I going wrong?

  • 1
    can you upload a screenshot of your dash app? you accidentally linked your local `http://127.0.0.1:8050/` which we can't see. also it would be helpful if we could have a sample of your dataframe so we can reproduce your plot. you can include the output from `final_api.head().to_dict()` directly into your question – Derek O Dec 17 '22 at 06:45
  • 1
    ah sorry i did not realize that it was my own local app, i have edited the question now – Brie MerryWeather Dec 17 '22 at 11:36

1 Answers1

2

I haven't worked with Spectacle Editor before, but I downloaded and installed the latest version (0.1.6) and tried to embed an interactive plot in a presentation slide. I'll go through the steps I took to reproduce your error as well as a possible solution.

You probably already did the following, but I started by selecting Plotly & Dash:

enter image description here

Then I was prompted to provide an Embed Url:

enter image description here

As you noticed, if you place a link to a local dash app (like http://127.0.0.1:8050/) in the Embed Url box, the static image loads, but there is no interactivity when you start a slideshow. It may be a bug with Spectacle Editor or maybe local Dash apps aren't supported.

I don't know your entire use case, but from the code that you've included, it doesn't appear that plotly-dash is necessary because you are placing the figure in the Dash app, but you're not using callbacks or other html components besides html.Div for the figure.

I'd also point out even if you could embed a local dash app in your presentation and preserve the interactivity, it's not a stable solution – you would have to keep the dash app running constantly in order for your figure to show up in your spectacle editor presentation. If the dash app crashes, the figure disappears from the presentation.

If you only need to get an interactive figure into your Spectacle Editor presentation, you can use Chart Studio – I'll go through the steps outlined in this article, as well as in the plotly and Chart Studio documentation here:

  1. In your terminal (or integrated terminal in VSCode), run the following: pip install chart_studio
  2. Create a Chart Studio account here
  3. Go to the API keys panel, generate an API key, and copy it. Then at the top of your code after your other imports, you'll import chart_studio and set your credentials with the following lines (replace {username} and {api_key} with your own):
import chart_studio
chart_studio.tools.set_credentials_file(username={username}, api_key={api_key})
  1. Add the following import statement, and another line after your fig is created to upload the fig to chart studio:
import chart_studio.plotly as py

# create figure

py.plot(fig, filename = 'scatter-for-spectacle', auto_open=True)
  1. Run your .py file, and it will automatically open the chart studio url where your figure was uploaded
  2. Copy the url and paste it into the Spectacle Editor Embed Url box

Here is what my Spectacle Editor presentation looks like once I play a slideshow (notice the interactive toggle):

enter image description here

And here is the full code to create a sample figure and upload it to Chart Studio:

import pandas as pd
import plotly.express as px

import chart_studio
chart_studio.tools.set_credentials_file(username={username}, api_key={api_key})
## the config file will be set to public sharing by default

import chart_studio.plotly as py

final_api = pd.DataFrame(
    {'id': {0: 70.0, 1: 77.0,2: 78.0,3: 83.0,4: 84.0,5: 85.0,6: 90.0,7: 96.0,8: 124.0,9: 125.0},
    'commits': {0: 32, 1: 32, 2: 32,3: 32,4: 37,5: 37,6: 10,7: 10,8: 10, 9: 10},
    'info_title': {0: 'SQAaaS API',1: 'SQAaaS API',2: 'SQAaaS API',3: 'SQAaaS API',4: 'Registry of Open Community Challenge API',5: 'Challenge API', 6: 'Onfido API',7: 'Onfido API', 8: 'Onfido API',9: 'Onfido API'},
    'API Age': {0: 74, 1: 74, 2: 74, 3: 74, 4: 22, 5: 22, 6: 124, 7: 124,8: 124, 9: 124},
    'Total_Versions': {0: 1, 1: 1, 2: 1, 3: 1,4: 1,5: 1, 6: 3, 7: 3,8: 3, 9: 3}}
)

fig = px.scatter(final_api, x="API Age", y="Total_Versions", color="commits", hover_name="info_title", height=900, width=1000, size='Total_Versions', size_max=30,color_continuous_scale=px.colors.sequential.Inferno)
fig.update_layout(
    height=600,
    width=600,
    template='ggplot2',
    yaxis_title=" Total number of versions",
    xaxis_title="Age of the API (in days)",
    yaxis_range=[0, 180],
    hoverlabel=dict(font_size=16, font_family="PT Sans"),font=dict(size=20, family='PT Sans'), paper_bgcolor='rgba(233,233,233,100)'
)
fig.update_xaxes(showline=True, linewidth=1, linecolor='black', mirror=True)
fig.update_yaxes(showline=True, linewidth=1, linecolor='black', mirror=True)

py.plot(fig, filename = 'scatter-for-spectacle', auto_open=True)
Derek O
  • 16,770
  • 4
  • 24
  • 43
  • 1
    Thank you so much your answer, I already tried this, and the issue is this particular plot visualizes the entire dataset which is around 27MB, and when I run the code it gives me the error: `This file is too big! Your current subscription is limited to 524.288 KB uploads` , I tried creating the scatterplot in plotly chart studio by manually updating the dataset, but since the size is heavy, it keeps on crashing. I tried deploying it to a website as well(i thought local files might not be supported), but the interactivity still remains disappeared. I think this is probably a bug with spectacle. – Brie MerryWeather Dec 18 '22 at 20:36
  • 1
    I see – that's a tough issue because of how large the file is. However, I just tried embedding a dash app from one of my personal projects into `Spectacle Editor` and it works – the interactivity is fully preserved when you begin a slideshow. How did you deploy your dash app to a website and what's the url if you don't mind sharing? – Derek O Dec 18 '22 at 21:57
  • It was preserved? I wonder then if I am doing something wrong, I deployed it on pythonanywhere.com, the website is this: [link](http://deepansha16.pythonanywhere.com/). I even tried embedding this but for me it does not show the hover, does there need to be some addition in my code? I followed this tutorial for the deployment: [link](https://towardsdatascience.com/the-easiest-way-to-deploy-your-dash-app-for-free-f92c575bb69e) – Brie MerryWeather Dec 18 '22 at 22:00
  • 1
    I think the issue is that you'll want to provide the `.app` file to the `embed url`, not the url for your webpage. For example, my personal project which is also a dash app is hosted on the google cloud, and I use that link to embed the dash app on my website, and I successfully used that same link to get a Dash app running on Spectacle Editor – what I can do is write up a separate answer to explain how I deployed my dash app to google cloud – Derek O Dec 18 '22 at 22:57
  • 1
    If you could help me out with this that would be really great, I am still a bit confused. – Brie MerryWeather Dec 18 '22 at 23:02
  • 1
    I just rechecked my dash app and unfortunately I realized I made a mistake – my dash app has buttons, text boxes, callbacks... and all of these things worked when embedded in `Spectacle Editor` but the hovering specifically is no longer functional – this leads me to believe that for any Dash app you embed in Spectacle Editor, no matter where you're hosting it from, hovering won't work in a Spectacle Editor slideshow. So unfortunately it seems that you either have to pay to upgrade Chart Studio so you can store a larger figure, or try to find an alternative to Spectacle Editor :/ – Derek O Dec 18 '22 at 23:47
  • I believe the same, I tried a couple of times but no avail, the best option will to be display it side by side on the website, I think they have some issues for Dash apps, but guess it was never worked on as Spectacle editor is not that commonly known. – Brie MerryWeather Dec 19 '22 at 06:56