Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2023 11:47 PM
@Marcela Bejarano :
The error you are seeing is because the dbutils module requires a valid notebook context to run the notebook. When running code from an ipywidget context, the main thread and the widget thread are different. To solve this, you can try setting the notebook context before calling dbutils.notebook.run()
import ipywidgets as widgets
from ipywidgets import interact, Box
from pyspark.sql import SparkSession
button = widgets.Button(description='Run model')
out = widgets.Output()
def on_button_clicked(b):
button.description = 'Run model'
with out:
# Get the current notebook context
current_notebook = get_ipython().get_parent()
# Set the notebook context for dbutils
dbutils.notebook.setContext(current_notebook)
# Run the notebook
dbutils.notebook.run("/mynotebookpath",60)
button.on_click(on_button_clicked)
widgets.VBox([button, out])This should set the notebook context correctly and allow you to run the notebook from the ipywidget context.