immutable values

I have a notebook which inputs a value from another notebook to set the default value for a slider which in turn updates that value being displayed from the other notebook. The problem is this is a circular definition.

I’m wondering if it’s possible to have a set of values that are set once and then frozen as immutable, in this case the default value might be set on page load then this circular reference should not be an issue.

Can this be done or planned for?

Could you share a minimal example pair of notebooks of what you’re trying to do? As far as I can tell, in notebook 1, you have something like this:

import {value} from 'notebook-2'

which is used to:

viewof slider = html`<input type="range" value="${value}">`

But I’m not sure I understand what you mean here:

It sounds like there might be something else that you’re importing from notebook 2 that slider controls?

In case it helps, note that you can import multiple independent copies of a notebook as long as your import statements use the with syntax; e.g. this

import {chart} with {slider as value} from 'notebook-2'

imports chart from an independent “copy” of notebook 2 (independent of the import that gives us value above) with slider standing in for value

Sure. In https://observablehq.com/@bgits/status-network-combined-utility-values

There is a slider: dappLocalProbabilityOfFailure which is then used as {dappLocalProbabilityOfFailure as probabilityOfFailure} from '@bgits/status-dapp-store-utility-value-exploration'

However I would like to use probabilityOfFailure from @bgits/status-dapp-store-utility-value-exploration as the initial value of dappLocalProbabilityOfFailure without creating a circular dependency.

Hmm, I can’t test this properly because CORS restrictions on your data source break my fork (interestingly enough I guess it works in the compare link), but is what you want achieved by the following?

At the bottom, I import another independent copy of @bgits/status-dapp-store-utility-value-exploration

import {probabilityOfFailure as initProbabilityOfFailure} from '@bgits/status-dapp-store-utility-value-exploration'

(This is independent from the other import of that notebook because the other one uses the import...with syntax and this one doesn’t.)

Then I edit viewof dappLocalProbabilityOfFailure:

viewof dappLocalProbabilityOfFailure = slider({
  min: 0, 
  max: 1, 
  step: .01, 
  value: initProbabilityOfFailure, 
  title: "Probability of failure for DApp Store", 
  description: "The probabilty that this project in isolation will fail"
})