Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Achieving the equivalent of Google CoLab @param markup in Jupyter without CoLab

Google Colab has some unique embedded markdown features which are not present in Jupyter markdown.

For example, this produces a slider:

#@title SEIR Model with Social Distancing { run: "auto" }
#@markdown 
#@markdown Reproduction number
R0 = 2.4 #@param {type:"slider", min:0.9, max:5, step:0.1}

Attempts to run Colab locally seem to be negative: CoLab notebooks must pass through the Google CoLab website to operate.

What is the best way to produce the equivalent of the @param markup from CoLab in an open-source way that works on Jupyter in a locally run notebook without going through an external website?

like image 472
Lars Ericson Avatar asked Jun 28 '20 20:06

Lars Ericson


1 Answers

I've struggled with the same problem and I solved it by using ipywidgets Jupyter Widgets documentation It is not as elegant, but works.

@interact_manual(R0 = (0.9,5.1,0.1))
def my_function(R0 = 2.4):
   print("SEIR Model with Social Distancing")
   print("Reproduction number")
   print(R0) # do something - enter your code here
   

What happens is, you will get a slider with your min/max values and a step. I am using _manual - you can set multiple parameters and after you've set them the way you want, you can click on the "Run Interact" button, which calls your function (e.g. my_function).

Image: Widget in VSCode

Works with VS-Code but not PyCharm

like image 102
Tatookie Avatar answered Sep 18 '22 15:09

Tatookie