Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

Simple x,y, plot from editable DataTable ValueError

$
0
0

@f1uffstar wrote:

Hi. I am new to dash, and trying to implement the simplest (apparently) of apps, which is an x,y graph of input Float data to an editable table. I did a search, but all the questions were involving far more complex apps.

With this code, I get a ValueError that the Shape of passed values is wrong, indices imply (2, 4) but the passed data is always (2, n) where n is the number of rows.

Please can somebody help me, I can’t understand why this isn’t working. I’m assuming it’s something to do with the way I’m passing the data between the DataTable and the dcc.Graph. I had to add the “data” property of the layout in order to have a cell to select to paste my data into. Is this where the error is?

Thanks so very much in advance!!

import dash
from dash.dependencies import Input, Output
import dash_table
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd

app = dash.Dash(__name__)

app.layout = html.Div([
    dash_table.DataTable(
        id='table-editing-simple',
        columns=([{
            'id': 'Pressure',
            'name': 'P_Gpa',
            'type': 'numeric'
        }, {
            'id': 'Temperature',
            'name': 'T_degC',
            'type': 'numeric'
        }]
        ),
        data=[{'P_Gpa':0, 'T_degC':0}
        ],
        editable=True
    ),
    dcc.Graph(id='table-editing-simple-output')
])


@app.callback(
    Output('table-editing-simple-output', 'figure'),
    [Input('table-editing-simple', 'data'),
     Input('table-editing-simple', 'columns')])
def display_output(rows, columns):
    df = pd.DataFrame(rows, columns)
    return {
        dcc.Graph(
            figure={
                "data": [{
                    "x": df['P_Gpa'],
                    "y": df['T_degC']
                }]
            })
    }

if __name__ == '__main__':
    app.run_server(debug=True)

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 6271

Trending Articles