Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
matt-sd-watson opened this issue Dec 15, 2023 · 1 comment
Labels
bug something broken P3 backlog sev-2 serious problem

Comments

@matt-sd-watson
Copy link

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'}
@Coding-with-Adam Coding-with-Adam added bug something broken sev-2 serious problem P2 considered for next cycle labels Jan 2, 2024
@Coding-with-Adam Coding-with-Adam removed the P2 considered for next cycle label Jan 18, 2024
@matt-sd-watson
Copy link
Author

Pinging here to see if there were any updates on this. I am continung to receive this error and it prevents certain callbacks from firing properly, such as when I want to export the current canvas from dcc.Graph as HTML. For example, with the following shapes contained in my go.Figure:

print(fig['layout'['shapes'])
[{'editable': True, 'fillcolor': 'rgba(0, 0, 0, 0)', 'fillrule': 'evenodd', 'label': {'text': ''}, 'layer': 'above', 'line': {'color': 'white', 'dash': 'solid', 'width': 4}, 'opacity': 1, 'path': 'M243.25,230.44512195121953L288.9817073170732,158.18902439024393L299.9573170731707,141.72560975609758L302.7012195121951,130.75000000000003L299.0426829268293,117.03048780487805L287.1524390243903,101.48170731707317L271.6036585365854,94.16463414634147L250.5670731707317,92.33536585365854L181.96951219512198,106.0548780487805L167.33536585365857,103.3109756097561L128.9207317073171,80.44512195121952L117.03048780487805,77.70121951219512L111.54268292682927,80.44512195121952L100.56707317073172,113.3719512195122L98.73780487804879,168.25000000000003L103.3109756097561,183.7987804878049L118.85975609756099,203.00609756097563L156.359756097561,220.38414634146343L175.56707317073173,226.78658536585368L204.83536585365857,245.9939024390244Z', 'type': 'path', 'xref': 'x', 'yref': 'y'}, {'line': {'color': 'white', 'width': 2, 'dash': 'solid'}, 'type': 'line', 'x0': 0.9299999999999999, 'x1': 0.95, 'xref': 'paper', 'y0': 0.05, 'y1': 0.05, 'yref': 'paper', 'editable': True, 'label': {'text': ''}, 'layer': 'above', 'opacity': 1, 'fillcolor': 'rgba(0,0,0,0)', 'fillrule': 'evenodd', 'path': 'M243.25,230.44512195121953L288.9817073170732,158.18902439024393L299.9573170731707,141.72560975609758L302.7012195121951,130.75000000000003L299.0426829268293,117.03048780487805L287.1524390243903,101.48170731707317L271.6036585365854,94.16463414634147L250.5670731707317,92.33536585365854L181.96951219512198,106.0548780487805L167.33536585365857,103.3109756097561L128.9207317073171,80.44512195121952L117.03048780487805,77.70121951219512L111.54268292682927,80.44512195121952L100.56707317073172,113.3719512195122L98.73780487804879,168.25000000000003L103.3109756097561,183.7987804878049L118.85975609756099,203.00609756097563L156.359756097561,220.38414634146343L175.56707317073173,226.78658536585368L204.83536585365857,245.9939024390244Z'}]

I still receive this error:

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

despite removing this key from the all of the shapes in the shape dictionary through the callback.

@gvwilson gvwilson self-assigned this Jul 11, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added the P3 backlog label Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P3 backlog sev-2 serious problem
Projects
None yet
Development

No branches or pull requests

3 participants