-
Notifications
You must be signed in to change notification settings - Fork 32
Conversation
This new index will serve as our playground for making a client-side version of the app
@@ -0,0 +1,51 @@ | |||
export const appLayout = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the super simple example to get started.
@@ -0,0 +1,299 @@ | |||
import R from 'ramda'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crossfiltering! This example demonstrates simple crossfiltering. The flow being:
- The
selectedData
andhoverData
properties of each graph get updated when their events get fired. - This data gets fed into a
Filter
component. - The output of the
Filter
component gets fed into the opposite graph. - There is a separate
Filter
component for each graph
Some things to note:
- We could add another
TextInput
and anotherFilter
item to further filter out the data - The select box clears on
newPlot
. We'll need a way to persist this box acrossnewPlot
calls
@@ -0,0 +1,323 @@ | |||
import R from 'ramda'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example is a little bit more complicated:
- There are a few custom components (in the
example_components.react
file): aFilter
,Table
, and aDataStore
component - The
Dropdown
elements and the textInput
element update the properties of theFilter
component. - The output of the
Filter
component updates the secondary table and the chart (the orange dots). - Set the
"animation=true"
property of the graph to show some smooth transitions for fun.
To run these examples: Step 1 - Build the bundle:
I use a combination of
In a separate terminal, start a local file serving server. For example:
then visit this server in your web browser (e.g. localhost:8000) |
* Examples need to export appLayout and mapInputsToOutputs | ||
* objects. | ||
*/ | ||
import {appLayout, mapInputsToOutputs} from './local_examples/example_1_input_to_div'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To create a new example, just change this import. And make sure that the examples that you write export an appLayout
and a mapInputsToOutputs
object.
|
||
] | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appLayout
object describes what the app looks like. Technically, it recursively generates the tree of react components.
dash_core_components
and dash_html_components
are loaded up in the index.html
file. Here is the source for the dash_core_components
: https://github.com/plotly/dash-core-components/tree/master/src/components
id: 'my-input', | ||
property: 'value' | ||
} | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mapInputsToOutputs
describes out properties of input components (as specified in the appLayout
) map to a single property of a single output component. Updates happen reactively, so whenever an input changes, the output transform
function gets called with those input properties and then the output property gets updated with that new value.
* objects or arrays, arithmetic, etc. | ||
*/ | ||
transform: inputArguments => { | ||
return `You've entered: ${inputArguments['my-input.value']}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inputArguments
is an object with keys that are the id
and the property
of the inputs
, separated by a .
.
* Of course, we can't have functions in the actual spec, | ||
* but we could introduce a lightweight transformation | ||
* language for modifying strings, accessing values in | ||
* objects or arrays, arithmetic, etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important point here! ^^
selectedData = R.pluck('customdata', inputArguments['graph-1-vs-2.selectedData']['points']); | ||
} | ||
return R.concat(hoverData, selectedData); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This transform uses a bit of JS, which can't be serialized as JSON. So, for this to work, we'd need to do one or more of the following:
- Design better input and output properties of components so that they can easily be declaratively composed with each other.
- Design a lightweight language for doing these types of operations (like we could just expose
Ramda
)
} | ||
|
||
render() { | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note how this component doesn't actually render itself on the page
} | ||
}); | ||
console.warn('filteredColumns: ', filteredColumns); | ||
setProps({filteredColumns}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setProps
is provided by dash-renderer
and performs the reactive updates across the app
filteredColumns: PropTypes.object | ||
} | ||
|
||
export const DataStore = props => null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DataStore
is super generic - you can pass whatever props in whatever form you want to it. In the examples it's being used to store columns={...}
but it could be used to store anything. Unlike filter, the properties that you supply to it never change.
|
||
window.dash_functional_components = { | ||
DataStore, Filter, Table | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dash-renderer
looks up the namespace
and type
of each component in the window
.
Closing this WIP in favor of https://github.com/plotly/streambed/issues/10927 |
No description provided.