ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 12 Apr 2021 08:23:26 +0200interact: different behavior concerning **kwargs in SageCell an Jupyter notebookhttps://ask.sagemath.org/question/56620/interact-different-behavior-concerning-kwargs-in-sagecell-an-jupyter-notebook/I'm trying to use the output of one interact as the input for number of control elements in a second interact. The following examle code works in Sage Jupyter notebook but fails in SageCell (Unfortunately I can't post a link to SageCell due to my low karma).
I don't understand why it fails and how I can make the code run in SageCell.
@interact
def f(s=slider([1,2], default=1)):
kwargs = { f"C_{i}": checkbox() for i in range(s)}
print(kwargs)
@interact(**kwargs)
def f2(**kwargs):
for key, value in kwargs.items():
print(f"{key} is {value}")
Mon, 12 Apr 2021 01:35:24 +0200https://ask.sagemath.org/question/56620/interact-different-behavior-concerning-kwargs-in-sagecell-an-jupyter-notebook/Answer by vdelecroix for <p>I'm trying to use the output of one interact as the input for number of control elements in a second interact. The following examle code works in Sage Jupyter notebook but fails in SageCell (Unfortunately I can't post a link to SageCell due to my low karma). </p>
<p>I don't understand why it fails and how I can make the code run in SageCell.</p>
<pre><code>@interact
def f(s=slider([1,2], default=1)):
kwargs = { f"C_{i}": checkbox() for i in range(s)}
print(kwargs)
@interact(**kwargs)
def f2(**kwargs):
for key, value in kwargs.items():
print(f"{key} is {value}")
</code></pre>
https://ask.sagemath.org/question/56620/interact-different-behavior-concerning-kwargs-in-sagecell-an-jupyter-notebook/?answer=56626#post-id-56626(partial answer) The reason why you have different behaviors is that `interact` in jupyter notebook is not the same object as `interact` in a cell. You can check that
print(type(interact), interact.__module__)
prints
- `<class 'ipywidgets.widgets.interaction._InteractFactory'> ipywidgets.widgets.interaction` in Jupyter notebook
- `<class 'function'> interact_sagecell` in the SageCellMon, 12 Apr 2021 08:23:26 +0200https://ask.sagemath.org/question/56620/interact-different-behavior-concerning-kwargs-in-sagecell-an-jupyter-notebook/?answer=56626#post-id-56626