Unable to incorporate plotly.express into a Mac App created using py2app and tkinter

Iโ€™m creating a Mac App using tkinter and py2app and am encountering problems when trying to incorporate plotly.express. (Python 3.7 on Mac OS 10.15.4)

The app asks the user for the time series length and overlays the plots of three random time series using that specified length along with the labels, โ€˜aโ€™, โ€˜bโ€™, and โ€˜cโ€™.

import numpy as np
import matplotlib.pyplot as plt
from tkinter import Tk, Label, Button, Entry,
import matplotlib.pyplot as plt
import plotly.express as px
import pandas as pd

window = Tk()
plt.switch_backend(โ€˜TkAggโ€™)

window.title(โ€œPlotterโ€)
window.geometry(โ€˜500x500โ€™)

length_label=Label(window, text=โ€œLengthโ€)
length_label.grid(row=0,column=0)

length = Entry(window,width=20)
length.grid(row=0,column=1)

โ€˜โ€™โ€˜Plot time seriesโ€™โ€™โ€™

def _plot():
np.random.seed(123)
num_times=int(length.get())
X = np.random.randn(num_times,3)
df=pd.DataFrame(X, columns=[โ€˜aโ€™,โ€˜bโ€™,โ€˜cโ€™])
df[โ€˜xโ€™] = df.index
df_melt = pd.melt(df, id_vars=โ€œxโ€, value_vars=df.columns[:-1])
fig=px.line(df_melt, x=โ€œxโ€, y=โ€œvalueโ€,color=โ€œvariableโ€)
fig.show()

plot_button = Button(master=window, text=โ€œPlotโ€, command=_plot)
plot_button.grid(row=1, column=0)

โ€˜โ€™โ€˜Quit Buttonโ€™โ€™โ€™
def _quit():
window.quit()
window.destroy()

quit_button = Button(master=window, text=โ€œQuitโ€, command=_quit)
quit_button.grid(row=2, column=0)

window.mainloop()

Iโ€™m able to create the app using py2app and run it from the terminal. The app opens when double clicking but hangs when I attempt to plot. Replacing the lines

df['x'] = df.index
df_melt = pd.melt(df, id_vars="x", value_vars=df.columns[:-1])
fig=px.line(df_melt, x="x", y="value",color="variable")
fig.show() 

with

plt.plot(df)
plt.show()

results in something that works absolutely fine, which suggests the problem is with plotly.express