Giter VIP home page Giter VIP logo

Comments (4)

Coding-with-Adam avatar Coding-with-Adam commented on May 23, 2024 1

Interesting request. Thanks for sharing the code, @Voltini

So, if we had this capability, once we set color=np.random.choice(["a", "b"], N), and you clicked on point 'b', the result you'd expect would be: 'marker.color': 'b' ?

from dash.

Voltini avatar Voltini commented on May 23, 2024 1

Hi Adam. Exactly, that's what I was thinking!

from dash.

Coding-with-Adam avatar Coding-with-Adam commented on May 23, 2024

Thank you for this feature request, @Voltini .
Can you please share a MRE with the scatter plots you mention?

from dash.

Voltini avatar Voltini commented on May 23, 2024

Sure, take for example the following code:

from dash import Dash, html, dcc, Input, Output
import plotly.express as px
import numpy as np

app = Dash(__name__)
N = 10
app.layout = html.Div(
    [
        html.Div(
            children=[
                dcc.Graph(
                    figure=px.scatter(
                        x=np.random.random(N),
                        y=np.random.random(N),
                        color=np.random.choice(["a", "b"], N),
                    ),
                    id="plot",
                )
            ],
        ),
        html.Div(id="example", children="Hello World"),
    ],
)


@app.callback(Output("example", "children"), Input("plot", "clickData"))
def call(clickdata):
    return str(clickdata)


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

When I click on a point I get:
{'points': [{'curveNumber': 0, 'pointNumber': 3, 'pointIndex': 3, 'x': 0.23940095437991715, 'y': 0.3631388501979541, 'bbox': {'x0': 605.27, 'x1': 611.27, 'y0': 260.14, 'y1': 266.14}}]}

However, if I change the color parameter in my plot to color=np.random.random(N) I get:

{'points': [{'curveNumber': 0, 'pointNumber': 4, 'pointIndex': 4, 'x': 0.11509044553896275, 'y': 0.41656166816663565, 'marker.color': 0.39641498810036235, 'bbox': {'x0': 329.76, 'x1': 335.76, 'y0': 270.62, 'y1': 276.62}}]}

As you can see now I have a marker.color attribute that was not present when my data was categorical.

Edit: Also it seems that the frontend already has access to the desired infromation, I don't know if this comment helps.
Screenshot 2024-02-07 113908

from dash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.