Plotly/Dash:在select/click/h上将选定的点(行)移动到数据框

2024-04-24 09:05:12 发布

您现在位置:Python中文网/ 问答频道 /正文

如果没有短跑是可能的,那就太好了,因为短跑看起来很硬。如果没有-请帮忙。你知道吗

例如,我在plot上有大纲视图,选择它们并移动到df。 在此之后,人们将看到这个“大纲视图”并解决问题

希望我问得好

https://github.com/plotly/plotly.js/issues/1847-也许这会有帮助?你知道吗

from IPython.display import IFrame
IFrame(src= "https://dash-simple-apps.plotly.host/dash-boxplot/", width="100%", height="650px", frameBorder="0")
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
from app import app
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
from dash.dependencies import Input, Output

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/Emissions%20Data.csv')

if 'DYNO' in os.environ:
    app_name = os.environ['DASH_APP_NAME']
else:
    app_name = 'dash-boxplot'

layout = html.Div([html.Div([
        html.H1("Greenhouse Gas Emissions by Continent")], style={"textAlign": "center"}),
        dcc.Graph(id="my-graph"),
        html.Div([dcc.RangeSlider(id="selected-continent",min=2008,max=2011,
                 marks={2008: "2008", 2009: "2009", 2010: "2010", 2011: "2011"},value=[2008, 2010],)],
                 style={"display": "block","margin-left": "auto","margin-right": "auto","width": "60%"}),
], className="container")


@app.callback(
    Output('my-graph', 'figure'),
    [Input('selected-continent', 'value')])
def update_figure(selected):
    dff = df[(df["Year"] >= selected[0]) & (df["Year"] <= selected[1])]
    traces = []
    for continent in dff.Continent.unique():
        traces.append(go.Box(y=dff[dff["Continent"] == continent]["Emission"],name=continent,marker={"size": 4}))
    return {"data": traces,
            "layout": go.Layout(title=f"Emission Levels for {'-'.join(str(i) for i in selected)}",autosize=True,
                                margin={"l": 200, "b": 100, "r": 200},xaxis={"showticklabels": False,},
                                yaxis={"title": f"Emissions (gigatonnes of CO2)","type": "log",},)}

这是从这里https://plot.ly/python/box-plots/(最后一个图)

我需要一个理想的悬停/选择副本


Tags: fromhttpsimportappdfoshtmlas