I am using Python 3.7.1 and Jupyter Notebook 6.0.1 via Anaconda.
I am attempting to run some basic analysis in Python using a function initialized by an ipywidget dropdown list to filter data. If the value in the dropdown changes, my desired state is to have the dropdown list remain on the screen, but refresh any data as filtered by the function. I have constructed the following example in an attempt to further test this out:
import ipywidgets as widgets
from IPython.display import clear_output
def mytest(x):
outs = widgets.Output()
outs.clear_output()
with outs:
lookhere = mytestfilter.value
if lookhere==1:
print("hello")
if lookhere==0:
print("goodbye")
display(outs)
mytestfilter = widgets.Dropdown(options={'night': 0, 'morning': 1}, description="FILTER")
display(mytestfilter)
outs=mytestfilter.observe(mytest, names='value')
Basically, in this example, the desired state would be to erase "hello" or "goodbye" and replace it with the proper term when "FILTER" is changed. Ultimately, this will be adapted to filter a pandas grid. I have tried using Ipython.display and assembling the function to an output to be cleared, however, depending on what I do, it is either clearing everything or clearing nothing.
Things I have tried: -I attempted moving the clear_output to the beginning of the function to clear anything existing. Since on the first run the "outs" variable does not exist, I also attempted housing this in an if statement as well as a try/except. It did not appear to do anything. -I have attempted different orders of assigning the variable, displaying the variable and clearing the output with no success.
My suspicion is the problem may partially be in the way the function is running and the variable exists inside the function. It seems as though it kicks off a new output and once the function is escaped, the output remains in the notebook regardless of what I attempt to clear the next time the function runs.
I referenced the following example when attempting to set up my test: https://github.com/jupyter-widgets/ipywidgets/issues/1744