4

I have a large dataset of around 500 parquet files with about 42 million samples.

In order to read those files I'm using Dask which does a great job.

In order to display them, I downsampled the Dask DataFrame in the most basic way (something like dd[::200]) and plotted it using Plotly.

So far everything works great.

Now, I had like to have an interactive figure on one side but I don't want it to open a web tab/to use jupyter/anything of this kind. I just want it to create a figure as matplotlib does.

In order to do so, I found a great solution that uses QWebEngineView:

plotly: how to make a standalone plot in a window?

My simplified code looks something like this:

import dask.dataframe as dd
import time
import plotly.graph_objects as go

def show_in_window(fig):
    import sys, os
    import plotly.offline
    from PyQt5.QtCore import QUrl
    from PyQt5.QtWebEngineWidgets import QWebEngineView
    from PyQt5.QtWidgets import QApplication

    plotly.offline.plot(fig, filename='temp.html', auto_open=False)

    app = QApplication(sys.argv)
    web = QWebEngineView()
    file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "temp.html"))
    web.load(QUrl.fromLocalFile(file_path))
    web.show()
    sys.exit(app.exec_())

def create_plot(df,x_param,y_param):
    fig.add_trace(go.Scattergl(x = df[x_param] , y = df[y_param], mode ='markers'))

fig = go.Figure()
ddf = dd.read_parquet("results_parq/*.parquet")
create_data_for_plot(ddf,'t','reg',1)
fig.update_layout(showlegend=False)

show_in_window(fig)

QUESTION:

Since the dataset is large and I want to use a smarter downsample method, I would like to use a library called plotly-resampler (https://predict-idlab.github.io/plotly-resampler/getting_started.html#how-to-use) which dynamically changes the amount of samples based on the zooming level. However, it uses Dash.

I thought to do something like:

fig = FigureResampler(go.Figure())
ddf = dd.read_parquet("results_parq/*.parquet")
create_data_for_plot(ddf,'t','reg',1)

show_in_window(fig)

This creates a plot with the smart resample but it does not change its resampling when the zoom changes (it basically stuck on its initial sampling).

Is there any solution that might give me a Dash figure in a separate window instead of a tab and yet to have the functionalities of Dash?

Thank you

Ben
  • 1,737
  • 2
  • 30
  • 61
  • As I understand u're trying to use the Plotly-Resampler lib (which is built on Dash) in a standalone window instead of a tab. AFAIK using Dash in a standalone window is not a built-in feature and would require some additional dev work. One approach you could try is to use a webview library (like QWebEngineView in ur current code) to display the Dash app in a standalone window. U would need to modify the Dash app to run without the Dash server and handle the communication between the app and the webview manually. Complex approach that would likely require good amount of dev effort to implement. – ggoer Jan 12 '23 at 14:24
  • 1
    The thing is that offline plots are restricted to "regular" interactions (plotly.js script in the html output), so using a QWebEngineView you would have to do the rescaling manually in javascript as well instead of using plotly-resampler (huge work). On the other hand, since the functionalities of plotly-resampler rely on Dash callbacks, you need a _server_ to run these callbacks. Would it be ok to have the plot displayed in a web browser window and have Dash/Flask running _locally_ on your machine ? – EricLavault Jan 14 '23 at 19:49

1 Answers1

0

I believe you could store it in a local file, then use the code

import webbrowser 
new = 2 # open in a new window, if possible

// open an HTML file on my own (Windows) computer
url = "file://d/testdata.html"
webbrowser.open(url,new=new)

to open it in a new window