✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Can't plot cones in dash

Using plotly 2.7.0, which has support for cones (https://plot.ly/python/3d-cone/), I’m trying to generate a mesh of cones on a sphere. I can generate the mesh in jupyter or ipython, however I get the traceback below when running in dash. For simplicity, I am only attempting to plot one cone below.

Is it expected that cones do not plot in dash?

import dash
from dash.dependencies import Input, Output, Event, State
import dash_core_components as dcc
import dash_html_components as html
import dash_table_experiments as dt
import plotly.graph_objs as go

app=dash.Dash()
app.scripts.config.serve_locally=True

server=app.server

app.layout=html.Div([
    html.Div([
        html.H1('Brownian Motion on the Unit Sphere'),
        html.H5('Warning, do not refresh the page or all data will be lost!'),
    ],className = 'container'),

    html.Button('Click to plot cone', id = 'plot_cone'),

    # 3d chart
    html.Div([
        html.Div([
            dcc.Graph(id='plot-3d-cone', style={'height': 600, 'align': 'center'},className='twelve columns')
        ],className='row')
    ],className='container'),

])

@app.callback(
    Output('plot-3d-cone', 'figure'),
    [Input('plot_cone', 'n_clicks')],
)
def plot_cone(n_clicks):
    cone = dict(
        type='cone',
        x=[1],
        y=[1],
        z=[1],
        u=[1],
        v=[0],
        w=[0]
    )

    # Set the layout
    noaxis=dict(showbackground=False,
                  showgrid=False,
                  showline=True,
                  showticklabels=True,
                  ticks='',
                  title='',
                  zeroline=False)

    layout3d=go.Layout(title='Brownian Motion on Unit Sphere',
            font=dict(family='Balto', size=14),
        )

    fig=go.Figure(dict(data=[cone], layout=layout3d))

    return fig

Traceback
[2018-06-19 13:31:10,327] ERROR in app: Exception on /_dash-update-component [POST]
Traceback (most recent call last):
File “/network/rit/lab/schiraldilab/bin/anaconda3/lib/python3.6/site-packages/flask/app.py”, line 2292, in wsgi_app
response = self.full_dispatch_request()
File “/network/rit/lab/schiraldilab/bin/anaconda3/lib/python3.6/site-packages/flask/app.py”, line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File “/network/rit/lab/schiraldilab/bin/anaconda3/lib/python3.6/site-packages/flask/app.py”, line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File “/network/rit/lab/schiraldilab/bin/anaconda3/lib/python3.6/site-packages/flask/_compat.py”, line 35, in reraise
raise value
File “/network/rit/lab/schiraldilab/bin/anaconda3/lib/python3.6/site-packages/flask/app.py”, line 1813, in full_dispatch_request
rv = self.dispatch_request()
File “/network/rit/lab/schiraldilab/bin/anaconda3/lib/python3.6/site-packages/flask/app.py”, line 1799, in dispatch_request
return self.view_functionsrule.endpoint
File “/network/rit/lab/schiraldilab/bin/anaconda3/lib/python3.6/site-packages/dash/dash.py”, line 558, in dispatch
return self.callback_map[target_id]‘callback’
File “/network/rit/lab/schiraldilab/bin/anaconda3/lib/python3.6/site-packages/dash/dash.py”, line 515, in add_context
output_value = func(*args, **kwargs)
File “/network/rit/home/ns742711/schiraldilab/repos/earle-viz/test.py”, line 58, in plot_cone
fig=go.Figure(dict(data=[cone], layout=layout3d))
File “/network/rit/lab/schiraldilab/bin/anaconda3/lib/python3.6/site-packages/plotly/graph_objs/graph_objs.py”, line 1175, in init
super(Figure, self).init(*args, **kwargs)
File “/network/rit/lab/schiraldilab/bin/anaconda3/lib/python3.6/site-packages/plotly/graph_objs/graph_objs.py”, line 377, in init
self.setitem(key, val, _raise=_raise)
File “/network/rit/lab/schiraldilab/bin/anaconda3/lib/python3.6/site-packages/plotly/graph_objs/graph_objs.py”, line 432, in setitem
value = self._value_to_graph_object(key, value, _raise=_raise)
File “/network/rit/lab/schiraldilab/bin/anaconda3/lib/python3.6/site-packages/plotly/graph_objs/graph_objs.py”, line 543, in _value_to_graph_object
_parent=self, _parent_key=key)
File “/network/rit/lab/schiraldilab/bin/anaconda3/lib/python3.6/site-packages/plotly/graph_objs/graph_objs.py”, line 793, in create
return globals()[class_name](*args, **kwargs)
File “/network/rit/lab/schiraldilab/bin/anaconda3/lib/python3.6/site-packages/plotly/graph_objs/graph_objs.py”, line 158, in init
value = self._value_to_graph_object(index, value, _raise=_raise)
File “/network/rit/lab/schiraldilab/bin/anaconda3/lib/python3.6/site-packages/plotly/graph_objs/graph_objs.py”, line 1073, in _value_to_graph_object
raise exceptions.PlotlyDataTypeError(self, path)
plotly.exceptions.PlotlyDataTypeError: Invalid entry found in ‘data’ at index, ‘0’

Path To Error: [‘data’][0]

It’s invalid because it doesn’t contain a valid ‘type’ value.

Conda list
# packages in environment at /network/rit/lab/schiraldilab/bin/anaconda3:
#
# Name Version Build Channel
plotly 2.7.0 py36_1

This is very weird… I prefer to use plotly.graph_objs, and found that it should be able to make cones (https://plot.ly/python/reference/#cone), yet looking through the source code for my graph_objs, there is no defined class Cone…?
So the documentation states that cones should be supported, but it is not anywhere in the package (or in mine at least). Fingers crossed a plotly expert will stumble by this somehow. :thinking:

:wave:

These classes are dynamically generated, which is why you don’t find the source code (that will change soon in plotly.py 3.0.0: https://github.com/plotly/plotly.py/pull/942).

For now, you can workaroudn this issue by not using the graph_objs. graph_objs are 1-1 with dict, so you can just do dict(type='cone', x=..., y=..., z=...)

Thanks @chriddyp. I am on the correct dash_core_components version but am still receiving the traceback as noted above in the simple example, which basically boils down to:

Path To Error: [‘data’][0]

It’s invalid because it doesn’t contain a valid ‘type’ value.

I’ll keep digging around to see if I’m generating something incorrectly, but the dict(type=‘cone’) doesn’t seem to work either.

dash 0.21.1
dash-core-components 0.23.0
dash-html-components 0.11.0
dash-renderer 0.13.0
dash-table-experiments 0.6.0

Thanks for reporting @wxnick! If you open up your browser’s console and type:

Plotly.version

what gets printed out? For me, it looks like:
image

@chriddyp I’m seeing

plotly.version
“1.38.0”

Just to make sure we’re all testing the same thing, this is the version that should be working.

Note: not only is there no go.Cone, but graph_objs aren’t being used for the figure or layout either.

import dash
from dash.dependencies import Input, Output, Event, State
import dash_core_components as dcc
import dash_html_components as html
import dash_table_experiments as dt
import plotly.graph_objs as go

app = dash.Dash()
app.scripts.config.serve_locally = True

server = app.server

app.layout = html.Div([
    html.Div([
        html.H1('Brownian Motion on the Unit Sphere'),
        html.H5('Warning, do not refresh the page or all data will be lost!'),
    ], className='container'),

    html.Button('Click to plot cone', id='plot_cone'),

    # 3d chart
    html.Div([
        html.Div([
            dcc.Graph(id='plot-3d-cone', style={'height': 600,
                                                'align': 'center'}, className='twelve columns')
        ], className='row')
    ], className='container'),

])


@app.callback(
    Output('plot-3d-cone', 'figure'),
    [Input('plot_cone', 'n_clicks')],
)
def plot_cone(n_clicks):
    cone = dict(
        type='cone',
        x=[1],
        y=[1],
        z=[1],
        u=[1],
        v=[0],
        w=[0]
    )

    # Set the layout
    noaxis = dict(showbackground=False,
                  showgrid=False,
                  showline=True,
                  showticklabels=True,
                  ticks='',
                  title='',
                  zeroline=False)

    layout3d = dict(title='Brownian Motion on Unit Sphere',
                    font=dict(family='Balto', size=14))

    fig = dict(data=[cone], layout=layout3d)

    return fig


if __name__ == '__main__':
    app.run_server()
1 Like

That’s right, I didn’t strip out the unused imports.