Pluto.jl throws a multiple assigning error when trying to change the values of a variable

In Python, if you have a variable numbers = 5 and then in the next like you write numbers = 55 , the variable’s value is updated.

While using Pluto.jl, I declared a variable called y_axis . I decided to change the value of this variable in another cell but I am getting this error:

Multiple definitions for y_axis.

Combine all definitions into a single reactive cell using a `begin ... end` block.

Why doesn’t Pluto.jl let me change a variable? Let me show you exactly what I am talking about. This is the 1st cell:

begin
    
    countries_data_labels = ["Italy", "Germany", "Pakistan", "Turkey", "United Kingdom"];
    
    y_axis = DataFrame() # Creating an empty dataframe to populate the y-axis when plotting graphs.
    
    ...
end

And this is 2 cells below:

begin
    ...

    y_axis = select!(y_axis, Not([:One_million]));
end

I’m sure Pluto allows changing a variable without having to create a giant block of a cell but I don’t know how. I know that I can re-assign values to the same variable but I don’t want to have to do that in one cell.

What should be the value of y_axis if you access it in another cell? The one of the first or the second assignment?
Note that the execution order of cells in Pluto is determined based on their dependencies, not by their order in the sheet (the cell order is only used if there are no dependencies or they are the same).
This is an intentional design choice:

  • The cell ordering could be done to optimize didactics / the storyline of the notebook, independent of technical reasons (e.g. you could move all initial setup to the Appendix).
  • It avoids bugs / not reproducable states due to wrong cell ordering or order of manual cell execution (this happens quite often in Jupyter).
  • The dependency tree is a prerequisite for (efficient) reactivity.
1 Like