plotly / plotly/plotly.py

Error on shape editing with `dcc.Graph`: Invalid property specified for object of type plotly.graph_objs.layout.shape.label: 'texttemplate'

Open
#4,462 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3 sev-2
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

I use dash components in my Flask app to render shapes on a dcc.Graph figure input. Oftentimes, this involves appending a list of shapes to the graph using the formula below:

for center in center_list:
            center = region.centroid
            annotation = cluster_frame[cluster_frame['cell_id'] == mask_id]['cluster']
            if len(annotation) > 0:
                annotation = str(annotation.tolist()[0])
                # boundary[int(center[0]), int(center[1])] = mask_id
                shapes.append(
                    {'editable': False, 'line': {'color': 'white'}, 'type': 'circle',
                     'x0': (int(center[1]) - circle_size), 'x1': (int(center[1]) + circle_size),
                     'xref': 'x', 'y0': (int(center[0]) - circle_size), 'y1': (int(center[0]) + circle_size),
                     'yref': 'y',
                     'fillcolor': cluster_assignments[data_selection][annotation]})
        self.figure['layout']['shapes'] = shapes

In the example above, a series of circles are generated around centroids for objects in the graph.
This scheme generally works well, but occasionally there will be in the following error when calling go.Figure(self.figure):

Invalid property specified for object of type plotly.graph_objs.layout.shape.label: 'texttemplate'

When I evaluate the shapes, sometimes they have a strange property added to them:

{'editable': False, 'line': {'color': 'white'}, 'type': 'circle', 'x0': 763, 'x1': 779, 'xref': 'x', 'y0': 284, 'y1': 300, 'yref': 'y', 'label': {'texttemplate': ''}}

It appears that plotly will randomly generate the label portion of the shape dictionary with a blank text template, which causes an error. It seems to happen indiscriminately and without a discernible pattern.

By comparison, most shapes appear to have a valid dictionary structure:

{'editable': True, 'line': {'color': 'white'}, 'type': 'circle', 'x0': 796, 'x1': 812, 'xref': 'x', 'y0': 293, 'y1': 309, 'yref': 'y'}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the go.Figure(self.figure) call and inspect how shape dictionaries reach plotly.graph_objs.layout.shape.label. Reproduce with the provided circle shapes and compare cases with and without label.texttemplate; done means the reported intermittent invalid-property error is explained and no longer occurs for the shown input.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.