# How to have multiple watched inputs from a single cell?

**URL:** <https://talk.observablehq.com/t/how-to-have-multiple-watched-inputs-from-a-single-cell/203>\
**Category:** Uncategorized\
**Created:** [February 2, 2018, 2:41am UTC](https://talk.observablehq.com/t/how-to-have-multiple-watched-inputs-from-a-single-cell/203 "2018-02-02T02:41:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nstrayer](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/nstrayer/32/126_2.png) [@nstrayer](https://talk.observablehq.com/u/nstrayer)\
**Post date:** [February 2, 2018, 2:41am UTC](https://talk.observablehq.com/t/how-to-have-multiple-watched-inputs-from-a-single-cell/203/1 "2018-02-02T02:41:41Z")

</div>

Is there is any way to have multiple values exported from a given cell?

For instance, if want to make a ui with a bunch of sliders to control values in a simulation the only way I am aware of to do that is each slider in a separate cell. I tried using object unpacking in my cell declaration ala. `({val1, val2}) = { return {val1: 1, val2: 2}}` but it was a no-go.

Another way I could think of is to export a raw object and then in subsequent cells pluck of the fields you want, but that feels hacky and I’m not sure it would be smart about updating.

I feel like this may be a trivial question but I read through all the introduction notebooks and couldn’t see anything in this regard.

Thanks!

---

<div class="post-metadata">

**Author:** ![jbum](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jbum/32/31_2.png) [@jbum](https://talk.observablehq.com/u/jbum)\
**Post date:** [February 2, 2018, 5:26am UTC](https://talk.observablehq.com/t/how-to-have-multiple-watched-inputs-from-a-single-cell/203/2 "2018-02-02T05:26:50Z")

</div>

Instead of

> [@nstrayer](#):
>
> ({val1, val2}) = { return {val1: 1, val2: 2}}

try

```auto
    myDict = { 
    # ...
    return {val1: 1, val2: 2};
    }

```

then in other cells, use myDict.val1, myDict.val2 etc. I saw John Bannister using this in his planets sketch, and I tried it and it works pretty nicely! He was using it to expose callback functions.

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [February 2, 2018, 7:09am UTC](https://talk.observablehq.com/t/how-to-have-multiple-watched-inputs-from-a-single-cell/203/3 "2018-02-02T07:09:16Z")

</div>

We don’t support multiple exports from cells yet, but we’ve been considering destructuring exports exactly like you describe. Stay tuned! To continue the example, destructruing would provider shorter syntax equivalent to three cells (where `_` is an anonymous cell):

```auto
_ = ({val1: 1, val2: 2})

```

```auto
val1 = _.val1

```

```auto
val2 = _.val2

```

An implication of this design is that all exports (_val1_ and _val2_ here) would change simultaneously. Observable doesn’t do any value comparison when a cell yields a new value, so we would conservatively assume that all exported values have changed.

---

<div class="post-metadata">

**Author:** ![nstrayer](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/nstrayer/32/126_2.png) [@nstrayer](https://talk.observablehq.com/u/nstrayer)\
**Post date:** [February 2, 2018, 4:10pm UTC](https://talk.observablehq.com/t/how-to-have-multiple-watched-inputs-from-a-single-cell/203/4 "2018-02-02T16:10:37Z")

</div>

Makes sense. So perhaps a good way to deal with multiple inputs in a single dom element would be to export the `DOM` object from the cell and then have subsequent cells that pluck off the values of various inputs inside of it?

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [February 2, 2018, 5:59pm UTC](https://talk.observablehq.com/t/how-to-have-multiple-watched-inputs-from-a-single-cell/203/5 "2018-02-02T17:59:15Z")

</div>

Yes, that would work. Though I think I would only do that if you need to react to the inputs individually for performance reasons; a compound input with `viewof` is simpler and should be preferred if it performs acceptably. I’ve written up a summary of possible techniques here:

[https://beta.observablehq.com/@mbostock/multi-value-inputs](https://beta.observablehq.com/@mbostock/multi-value-inputs)

---

<div class="post-metadata">

**Author:** ![nstrayer](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/nstrayer/32/126_2.png) [@nstrayer](https://talk.observablehq.com/u/nstrayer)\
**Post date:** [February 2, 2018, 6:30pm UTC](https://talk.observablehq.com/t/how-to-have-multiple-watched-inputs-from-a-single-cell/203/6 "2018-02-02T18:30:04Z")

</div>

This is wonderful! Thanks so much! And thanks in general for dedicating your time to this tool. It’s a game changer.
