Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

POC - Client-Side Dash Apps #7

Closed
wants to merge 4 commits into from
Closed

POC - Client-Side Dash Apps #7

wants to merge 4 commits into from

Conversation

chriddyp
Copy link
Member

No description provided.

@@ -0,0 +1,51 @@
export const appLayout = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example-1

Copy link
Member Author

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';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example-3

Copy link
Member Author

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 and hoverData 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 another Filter item to further filter out the data
  • The select box clears on newPlot. We'll need a way to persist this box across newPlot calls

@@ -0,0 +1,323 @@
import R from 'ramda';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example-2

Copy link
Member Author

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): a Filter, Table, and a DataStore component
  • The Dropdown elements and the text Input element update the properties of the Filter 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.

@chriddyp
Copy link
Member Author

To run these examples:

Step 1 - Build the bundle:

git clone https://github.com/plotly/dash-renderer.git
cd dash_renderer
npm run build-local 

I use a combination of ag and entr to rebuild automatically:

ag -l --js | entr npm run build-local

In a separate terminal, start a local file serving server. For example:

cd dash_renderer
python -m SimpleHTTPServer

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';
Copy link
Member Author

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.


]
}
};
Copy link
Member Author

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'
}
],
Copy link
Member Author

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']}`;
Copy link
Member Author

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.
Copy link
Member Author

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);
}
Copy link
Member Author

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;
Copy link
Member Author

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});
Copy link
Member Author

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;
Copy link
Member Author

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
};
Copy link
Member Author

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.

@chriddyp
Copy link
Member Author

Closing this WIP in favor of https://github.com/plotly/streambed/issues/10927

@chriddyp chriddyp closed this Jun 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant