Databricks notebook ipywidgets not working as expected ( button click issue)
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2023 02:37 AM
I am working on Azure databricks(IDE). I wanted to create a button which takes a text value as input and on the click of a button a function needed to be run which prints the value entered.
For that I created this code:
from IPython.display import display
import ipywidgets as widgets
def my_function(param):
print(f"The parameter is: {param}")
text_input = widgets.Text(description="Enter text:")
button = widgets.Button(description="Click Me!")
display(text_input)
display(button)
def on_button_click(b):
my_function(text_input.value)
button.on_click(on_button_click)But when I click the button, nothing happens. It should run the `my_function` and print the input text.
Strangely this exact code works fine when I run it in **jupyter notebook**.
I am not able to make it work in **Azure Databricks**.
Any insights would be helpful
Labels: