2

I need a widget that takes in an array as input, i.e. something like a hundred sliders (that I don't want to create manually).

How can I achieve this?

I thought the answer would be widgets.Box, but then I get the error Box(...) cannot be transformed to a widget.

0

2 Answers 2

0

Got it -- the trick is to use **kwargs. My code looks something like this.

seed = np.zeros(100)
kwargs = {'seed[{}]'.format(i) : 
          widgets.FloatSlider(
              min = -1.0, 
              max = 1.0, 
              step = 0.01, 
              value = seed[i]) 
          for i in range(100)}

@interact(**kwargs)
def Generate(**kwargs):
  return seed

A better solution will nonetheless be appreciated, because I don't know how to change the layout and stuff with this solution.

Sign up to request clarification or add additional context in comments.

Comments

0

I think you need HBox or VBox, not just Box for a container.

import ipywidgets as widgets
from ipywidgets import interact
n = 10
seed = np.zeros(n)
sliders = list(widgets.FloatSlider(
              description = 'seed[{}]'.format(i),
              min = -1.0, 
              max = 1.0, 
              step = 0.01, 
              value = seed[i]) 
          for i in range(n))

widgets.VBox(children = sliders)

1 Comment

No, this is not the problem -- widgets.Box works here too. It is only when one actually puts an interact script with the Box (or VBox) widget that you get the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.