Hello World in Jupyter Notebook and Mercury
Let's create a simple web app that asks user for name and display greetings.
During notebook development you can interact with widget. Its value will be updated. However, you need to manually execute cells to see a change.
Cells are automatically re-executed when running notebook as Mercury App. Mercury re-execute cell with widget definition and cells below.
Required packages
You will need mercury
package for this example.
Notebook
Import package:
import mercury as mr
Create a Text
widget:
name = mr.Text(value="Piotr", label="What is your name?")
Print widget value:
print(f"Hello {name.value}")
Cell 2 and 3 will be automatically re-executed after widget update when running as Mercury App.
Please save notebook as hello-world.ipynb
file. Mercury will set hello-world
as web app title.
If you want to set different title please check the App
class.
The screenshot of code in the Jupyter Notebook:
Mercury App
Please start Mercury with the following command:
mercury run
Open web browser at address http://127.0.0.1:8000
, you will see your notebooks.
Please select card with your notebook. You can set name value and press Enter
to see a change.