|
3 | 3 | Dash components |
4 | 4 | =============== |
5 | 5 |
|
6 | | -The ``dpd-components`` package contains ``Dash`` components. |
| 6 | +The ``dpd-components`` package contains ``Dash`` components. This package is installed as a |
| 7 | +dependency of ``django-plotly-dash``. |
7 | 8 |
|
8 | 9 | .. _pipe_component: |
9 | 10 | The ``Pipe`` component |
10 | 11 | -------------- |
11 | 12 |
|
12 | | -Blah |
| 13 | +Each ``Pipe`` component instance listens for messages on a single channel. The ``value`` member of any message on that channel whose ``label`` matches |
| 14 | +that of the component will be used to update the ``value`` property of the component. This property can then be used in callbacks like |
| 15 | +any other ``Dash`` component property. |
| 16 | + |
| 17 | +An example, from the demo application: |
| 18 | + |
| 19 | +.. code-block:: python |
| 20 | +
|
| 21 | + import dpd_components as dpd |
| 22 | +
|
| 23 | + app.layout = html.Div([ |
| 24 | + ... |
| 25 | + dpd.Pipe(id="named_count_pipe", # ID in callback |
| 26 | + value=None, # Initial value prior to any message |
| 27 | + label="named_counts", # Label used to identify relevant messages |
| 28 | + channel_name="live_button_counter"), # Channel whose messages are to be examined |
| 29 | + ... |
| 30 | + ]) |
| 31 | +
|
| 32 | +The ``value`` of the message is sent from the server to all front ends with ``Pipe`` components listening |
| 33 | +on the given ``channel_name``. This means that this part of the message should be small, and it must |
| 34 | +be JSON serialisable. Also, there is no guarantee that any callbacks will be executed in the same Python |
| 35 | +process as the one that initiated the initial message from server to front end. |
| 36 | + |
| 37 | +The ``Pipe`` properties can be persisted like any other ``DashApp`` instance, although it is unlikely |
| 38 | +that continued persistence of state on each update of this component is likely to be useful. |
| 39 | + |
| 40 | +This component requires a bidirectional connection, such as a websocket, to the server. Inserting |
| 41 | +a ``plotly_message_pipe`` :ref:`template tag <plotly_message_pipe>` is sufficient. |
0 commit comments