# Retrieve value from graph

**URL:** <https://talk.observablehq.com/t/retrieve-value-from-graph/4406>\
**Category:** Help\
**Created:** [December 30, 2020, 3:48pm UTC](https://talk.observablehq.com/t/retrieve-value-from-graph/4406 "2020-12-30T15:48:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emo-Lightning](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/emo-lightning/32/4060_2.png) [@Emo-Lightning](https://talk.observablehq.com/u/Emo-Lightning)\
**Post date:** [December 30, 2020, 3:48pm UTC](https://talk.observablehq.com/t/retrieve-value-from-graph/4406/1 "2020-12-30T15:48:55Z")

</div>

Hi!  
So, i want to get an array back from clicking on a certain square in a Heatmap…  
The issue i have is that i want to retrieve the value in an external cell and not the same graph cell because i want to use it as a global value (or something like that for usage in other cells)!  
For that i have tried to create a variable in a separate cell as such:  
val = data (where data is my original data so val is like a copy to not affect it)  
And in my heatmap cell code i have an onclick as such:  
combi.on(‘click’, function (d) {  
d3.select(this).select(“rect”).selectAll(function() {  
val.value = exp  
}) });  
In this example i was just trying to change the value to another array that i have (exp) when activating the click function but the ‘val’ didn’t change…  
In another way, i have seen something as “mutable” and even when i used it nothing changed.  
So, here’s the thing again:

1. how to change a value from a different cell?
2. how to retrieve the value from the clicked cell (unlike the simple change of ‘val’ in example)?  
I’m quite sure the function is quite wrong so excuse me for that 😃

---

<div class="post-metadata">

**Author:** ![tomlarkworthy](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tomlarkworthy/32/5940_2.png) [@tomlarkworthy](https://talk.observablehq.com/u/tomlarkworthy)\
**Post date:** [December 30, 2020, 4:13pm UTC](https://talk.observablehq.com/t/retrieve-value-from-graph/4406/2 "2020-12-30T16:13:18Z")

</div>

> **[Introduction to Mutable State](https://observablehq.com/@observablehq/introduction-to-mutable-state)**
>
> Observable notebooks are made of cells. Each cell is defined by a bit of code (just click on the left margin!) and will react to updates in any other cells it references. To take full advantage of this reactivity, we generally want to avoid mutation...

```
mutable val = data

```

```auto
f() {
   ...
   mutable val = newVal;
}

```

A cell can be triggered & read from a mutable just by depending on it as usual.

---

<div class="post-metadata">

**Author:** ![Emo-Lightning](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/emo-lightning/32/4060_2.png) [@Emo-Lightning](https://talk.observablehq.com/u/Emo-Lightning)\
**Post date:** [December 30, 2020, 5:07pm UTC](https://talk.observablehq.com/t/retrieve-value-from-graph/4406/3 "2020-12-30T17:07:35Z")

</div>

It worked!  
Thank you greatly for this as it helped me solve one of the 2 issues!  
Apparently i was using ‘mutable’ in a wrong way but now after seeing your examples it seemed that in the onclick function i changed ‘mutable val.value’ instead of just ‘mutable val’ which was the main issue…  
And, i edited to be only as such:  
combi.on(‘click’, function (d) {  
mutable val = d.values  
});  
so that i can solve the other issue of getting the selected data…  
Thanks again so much 🙂

---

<div class="post-metadata">

**Author:** ![tomlarkworthy](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tomlarkworthy/32/5940_2.png) [@tomlarkworthy](https://talk.observablehq.com/u/tomlarkworthy)\
**Post date:** [December 30, 2020, 7:50pm UTC](https://talk.observablehq.com/t/retrieve-value-from-graph/4406/4 "2020-12-30T19:50:33Z")

</div>

value like from an \<input\>?

```auto
click_handler = (event) => {
   mutable val = evt.target.value
}

```

---

<div class="post-metadata">

**Author:** ![Emo-Lightning](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/emo-lightning/32/4060_2.png) [@Emo-Lightning](https://talk.observablehq.com/u/Emo-Lightning)\
**Post date:** [December 30, 2020, 8:49pm UTC](https://talk.observablehq.com/t/retrieve-value-from-graph/4406/5 "2020-12-30T20:49:38Z")

</div>

ah. i already had that issue solved as i mentioned earlier by getting “d.value” on click… but thanks again for the reply!
