我们如何访问Plotly中的`dcc.store`的值?

huangapple go评论64阅读模式
英文:

How do we access the value of dcc.store in plotly

问题

I am using dash by plotly to create a dashboard. I want to save a variable from one page so I can use it in another page. I am trying to use dcc.store for the same. But while trying to access it, I am getting the following error: Property "value" was used with component ID: "getComm" in one of the Input items of a callback. This ID is assigned to a dash_core_components. Store component in the layout, which does not support this property.

This is the code in my index file:

dcc.Store(id='getComm')

It's value is being written in page1.py
And I am trying to access it in the callback in page2.py:

@callback(
	...
	Input('getComm', 'value')
)

How do we access the value in another page?

英文:

I am using dash by plotly to create a dashboard. I want to save a variable from one page so I can use it in another page. I am trying to use dcc.store for the same. But while trying to access it, I am getting the following error: Property "value" was used with component ID: "getComm" in one of the Input items of a callback. This ID is assigned to a dash_core_components. Store component in the layout, which does not support this property.

This is the code in my index file:

dcc.Store(id='getComm')

It's value is being written in page1.py
And I am trying to access it in the callback in page2.py:

@callback(
	...
	Input('getComm', 'value')
)

How do we access the value in another page?

答案1

得分: 1

You need to use data instead of value (see Store Properties) :

@callback(
    ...
    Input('getComm', 'data')
)

Also you might want to be specific about the storage_type (defaults to 'memory'), eg.

dcc.Store(id='getComm', storage_type='local')

Nb. You need to declare the dcc.Store in the main app file (eg. app.py) so that you can refer to it as a callback Input/Output/State in any of the pages within the app. See for example this demo.

英文:

You need to use data instead of value (see Store Properties) :

@callback(
    ...
    Input('getComm', 'data')
)

Also you might want to be specific about the storage_type (defaults to 'memory'), eg.

dcc.Store(id='getComm', storage_type='local')

Nb. You need to declare the dcc.Store in the main app file (eg. app.py) so that you can refer to it as a callback Input/Output/State in any of the pages within the app. See for example this demo.

huangapple
  • 本文由 发表于 2023年4月13日 18:57:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76004602.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定