Dash Chart Editor

Good day, All,

I have been working on a project recently that I think you all will be interested in.

Basically, I began wrapping the react-chart-editor that is provided by Plotly, for use directly with Dash.

This is an alpha release, as I would love feedback on people using it.

To install, pip install dash-chart-editor :slight_smile:

Try running the example apps in the dash-chart-editor GitHub

Thanks @AnnMarieW for your valuable time and aid with this project


Dash Chart Editor

Dash Chart Editor is a Dash component wrapper for the Plotly React Chart Editor package, enabling you to use an editor panel for Plotly charts in your Dash app.

Installation

pip install dash-chart-editor

Demo and Quickstart

chart-editor-quickstart

import dash_chart_editor as dce
from dash import Dash, html
import plotly.express as px


app = Dash(__name__, external_scripts=["https://cdn.plot.ly/plotly-2.18.2.min.js"])

df = px.data.gapminder()

app.layout = html.Div([
    html.H4("Dash Chart Editor Demo with the Plotly Gapminder dataset"),
    dce.DashChartEditor(
        dataSources=df.to_dict("list"),
    )
])


if __name__ == "__main__":
    app.run_server(debug=True)


Examples

See more demo apps in the /examples folder in GitHub.

21 Likes

Great work, I’ll give it a go! Thanks @jinnyzor

Amazing! :grinning:

Thanks for your contribution.

This is so awesome! it’s super cool and fun to play with :sunglasses:

Here is a quickstart app like the one in the original post. Amazing what you can do with 11 lines of code.

Give it a try:

:point_right: pip install dash-chart-editor==0.0.1a4

  1. quickstart.py
import dash_chart_editor as dce
from dash import Dash, html
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/solar.csv')
app = Dash(__name__, external_scripts=["https://cdn.plot.ly/plotly-2.18.2.min.js"])


app.layout = html.Div([
    html.H4("Dash Chart Editor Demo with the Plotly Solar dataset"),
    dce.DashChartEditor(dataSources=df.to_dict("list")),
])


if __name__ == "__main__":
    app.run_server(debug=True)


  1. Here is another app based on the pattern matching app in the Dash Example Index. It adds a dash-chart-editor for each figure:

ezgif.com-gif-maker (4)

7 Likes

It’s amazing. I’m just curious that can you add a function like every time the input information is changed, the code will appear at the bottom of the chart? So, users can look at it and can understand the settings of the chart more easily?

1 Like

Hello @hoatran,

Originally, that was the case, the figure would update every time a setting would change. This however did not catch when you moved annotations 100%, plus becomes a bit heavy on larger datasets.

You can pass a True to saveState of the dce, and this will grab the current state of the figure and give you the figure output. This is currently the most consistent way to get the info.

You can then look at the raw figure output, or clean the data (this removes the long lists that are in the data sections) using cleanDataFromFigure. This will make the output a little more legible.

5 Likes

@AnnMarieW && @jinnyzor Getting the word out per:

5 Likes

Thank you so much for sharing this, @jinnyzor! Looking forward to trying it out.

1 Like

Hi Jinnyzor,

Great work , as from demo its looks awesome.

When i am running the sample code , i am getting below error message .
what can be the issue and how to resolve it .
AttributeError: partially initialized module β€˜dash_chart_editor’ has no attribute β€˜DashChartEditor’ (most likely due to a circular import)

Thanks in advance

Hello @Awadhesh,

Please uninstall the library and then install it again.

If that doesnt work, then could you please post your code?

1 Like

Absolutely fantastic tool, well done and thank you!

Is there any chance of adding an example of how to save state? For example in the React live demo app you can select pre-saved plot combinations and I’m slightly struggling to see how to use saveState to do something similar.

HI @JamesIsCooke

You can use a button to save the state. Here is an example:

You can also see an example of using the chart editor to modify and save 3 different figures here:

4 Likes

reposting … some feedback fm one of my contacts

  1. It should ideally be like Mitosheet and generate the chart code, or the menu should be within a modal so it can be hidden.
  2. Would be great if this came wrapped in something like dragula, so multiple charts could be inserted on a page and moved around (something like Dashboard engine)
  3. Hard to configure the scales when it does not recognize a datatype (could be my user error)
2 Likes

1- You can recreate the chart using the built in functions and the figures that it creates. Storing a figure as a dictionary, then passing it to the chartToPython along with a df will update the data in the chart, which can be used as a figure in dcc.Graph.

2- Yes, but that’s really not where this chart editor belongs. I am going to hook this up to my dashboard-helper, which does just that.

3- Yes, the data types is hard to determine on the JS side. Everything has to be determine by looking at the strings. There may be a way to determine this better.

1 Like

This is very good, but if I want to know where to uniformly output the parameters after adjusting and changing the chart, because I want to apply the parameters to the Kanban chart developed by Dash

Hi @AnnMarieW where can I find the example code of the app shown in your GIF, the one which shows pattern matching along with DCE?

1 Like

Hello @jike-tansuo,

Welcome to the community!

Do you have an example of what you are trying to do exactly?

Very cool. I didn’t know there was a tool like this for react. I know the new one is for Dash, but I think it’ll be real helpful to setup what you want with fewer trips back and forth to get it just right.

Edit – Is it possible to view the code for the chart that’s generated? Question applies to both the new Dash, and prior React versions.

3 Likes

Hi @dataturnsmeon - You can find the pattern matching example here

2 Likes

This is so cool @jinnyzor !

Can we change the version of plotly js / plotly.py package being used under the hood by this wrapper?