Pluto Notebook Excessive Compute Time with PlotlyJS

I have a Pluto notebook with about 13 cells, most of which have a variable number of lines between the begin and end. When I take a look at the sum total of the time taken to execute each cell as reported by Pluto, it takes about 600 ms. The notebook was written fairly early on in my Julia programming experience, so is all written in the global scope. However 600 ms is acceptable.

The problem is that when I time the execution with a stopwatch, the time is about 30s. And it comes up with the message:

I can see which cell blocks update quickly and which ones don’t, but I don’t know why this message comes and why the time for update is much longer than that recorded by Pluto.

I have both

	using PlotlyJS
	using PlutoUI

which forced me to prepend the plots command with Plots as follows:

	plotlyjs()  # use for finding and annotating peaks
	plotMD = Plots.plot(1:nc-1,MDmean,
		title="MD $type Variation",
		legend=false, 
		size=(600,375),
		ylabel = "$type [$unit]",
		xlabel = "MD position [strip number]",
		xticks = 0:2:nc-1)

Not sure if this is significant.

It happens in both Julia 1.10.6 and 1.11.1.

I’ve never seen that message in a Pluto notebook but it looks like the kind of message you get when JavaScript crashes and burns…I bet there are errors showing up in the console of the browser, but I’m not sure how much help they will be…?

The Julia session shows the following:

julia> using Pluto

julia> Pluto.run()
[ Info: Loading...
┌ Info:
└ Opening http://localhost:1234/?secret=6QRRwPv8 in your default browser... ~ have fun!
┌ Info:
│ Press Ctrl+C in this terminal to stop Pluto
└
┌ Info: Removing compat entry for stdlib
└   p = "Statistics"
┌ Warning: The active manifest file has dependencies that were resolved with a different julia version (1.11.1). Unexpected behavior may occur.
└ @ C:\Users\jakez\AppData\Local\Temp\jl_BveW2q\Manifest.toml:0
┌ Info: Operation failed. Updating registries and trying again...
└   exception = Could not locate the source code for the StyledStrings package. Are you trying to use a manifest generated by a different version of Julia?
    Updating registry at `C:\Users\jakez\.julia\registries\local_julia_registry`
    Updating git-repo `https://github.com/Spectrum-Tec/local_julia_registry`
    Updating registry at `C:\Users\jakez\.julia\registries\General.toml`
┌ Warning: Operation failed. Removing Manifest and trying again...
│   exception = Could not locate the source code for the StyledStrings package. Are you trying to use a manifest generated by a different version of Julia?
└ @ Pluto C:\Users\jakez\.julia\packages\Pluto\esC4R\src\packages\Packages.jl:496

This is after I ran Pkg.instantiate, Pkg.resolve, Pkg.update to try and coax it to play nice with 1.10.6 after using 1.11.1 for a while. Problem remained with both. I was wondering if I should remove the PlotlyJS dependency and see what happens. Thinking back the problem may have started when I switched from Plotly to PlotlyJS. I did that to get savefig() to work. I will experiment a bit more when I get a chance.

The cell that is causing the problem is:

begin
	#plotlyjs()  # use for finding and annotating peaks
	wavelength = 1.0 ./ stripsf[:,1]  # spatial frequency converted to wavelength
	i = findlast(x -> x >= 1, wavelength) + 1   # don't plot high wavelength data
	abscissa = reverse(wavelength[i:end])
	ordinate = reverse(sqrt.(averagef[i:end]./2.0))
	plotCDf = Plots.plot(abscissa, ordinate,
		title="CD $type Variation Frequency",
		legend=false, 
		size=(600,375),
		ylabel="$type [$unit]",
		xlabel="CD wavelength [m]",
		xlims=(0, 1))
	threshold = 0.05
	idx = findall(x -> x > threshold, ordinate)
	#idx = [idx[1], idx[3], idx[5]]
	#idx = idx[1:3]
	for n in idx  # perform annotation
		annotate!(abscissa[n], ordinate[n], text("($(round(abscissa[n];digits=3)),
		$(round(ordinate[n];digits=2)))", 10, :left))
	end
	figname = splitext(filename)[1] * "_avgSpectrum.png"
	#Plots.savefig(plotCDf, figname)
	plotCDf
	#==#
end

When the default plots backend is used the last line plotCDf goes into an infinite loop or something, I never get control back. When the last line is commented out then the cell behaves normally.

With more fiddling and reading how things work in the REPL, I tried the following in the Pluto notebook.

	using Plots
	import PlotlyJS  # instead of `using PlotlyJS`
    plotlyjs()

This seems to have solved the problem. It should probably be documented somewhere.

Edit: Premature comment above it is still exhibiting the same problematic behaviour.

I just remembered GitHub - JuliaPluto/PlutoPlotly.jl Maybe it could be of use?

1 Like

I tried a simple example using PlutoPlotsly.

begin
	using PlutoPlotly
	x = range(0, stop=6π, length=500)
	y=sin.(x)
	plot(x,y,title="Title", xlabel="freq", ylabel="Amp")
end

Outside of the notebook the title and labels plot correctly when I am using Plots. However the code as shown in the Pluto notebook displays the plot but not the title or text.