plotly / dash-table-experiments

NO LONGER SUPPORTED - use https://github.com/plotly/dash-table instead
MIT License
174 stars 57 forks source link

There was an incomprehensible mistake. It worked before the loading of the class Tab. #52

Open alexbeo opened 6 years ago

alexbeo commented 6 years ago

import base64 import datetime import io

import dash from dash.dependencies import Input, Output import dash_core_components as dcc import dash_html_components as html import dash_table_experiments as dt

import pandas as pd

BASE_NAMES = ('Date', 'Open', 'High', 'Low', 'Close', 'Vol', 'Z') date_col = BASE_NAMES[0]

app = dash.Dash()

app.scripts.config.serve_locally = True

app.layout = html.Div([ html.H1('Программа анализа финансовых временных рядов', style={ 'textAlign': 'center', 'margin': '10px' } ), dcc.Upload( id='upload-data', children=html.Div([ 'Load File ', html.A(' File Open') ]), style={ 'width': '100%', 'height': '60px', 'lineHeight': '60px', 'borderWidth': '1px', 'borderStyle': 'dashed', 'borderRadius': '5px', 'textAlign': 'center', 'margin': '10px' },

Allow multiple files to be uploaded

    multiple=True
),
html.Div(id='output-data-upload'),
html.Div(dt.DataTable(rows=[{}]), style={'display': 'none'})

])

def parse_contents(contents, filename, date): content_type, content_string = contents.split(',')

decoded = base64.b64decode(content_string)

try:
    if 'csv' in filename:
        # Assume that the user uploaded a CSV file
        df = pd.read_csv(io.StringIO(decoded.decode('utf-16')))
        del df['Z']
        del df['Vol']
        df['HO'] = round((df['High']/df['Open']-1),3)
        df['OL'] = round((df['Open'] / df['Low']-1),3)
        df['HL'] = round((df['High'] / df['Low']-1),3)
    elif 'xls' in filename:
        # Assume that the user uploaded an excel file
        df = pd.read_excel(io.BytesIO(decoded))
except Exception as e:
    print(e)
    return html.Div([
        'There was an error processing this file.'
    ])

return html.Div([
    # html.H5(filename),
    # html.H6(datetime.datetime.fromtimestamp(date)),

    # Use the DataTable prototype component:
    # github.com/plotly/dash-table-experiments
    dt.DataTable(rows=df.to_dict('records')),

    html.Hr(),  # horizontal line

    # For debugging, display the raw contents provided by the web browser
    # html.Div('Raw Content'),
    # html.Pre(contents[0:200] + '...', style={
    #     'whiteSpace': 'pre-wrap',
    #     'wordBreak': 'break-all'
    # })
])

@app.callback(Output('output-data-upload', 'children'), [Input('upload-data', 'contents'), Input('upload-data', 'filename'), Input('upload-data', 'last_modified')]) def update_output(list_of_contents, list_of_names, list_of_dates): if list_of_contents is not None: children = [parse_contents(c, n, d) for c, n, d in zip(list_of_contents, list_of_names, list_of_dates)] return children

app.css.append_css({ 'external_url': 'https://codepen.io/chriddyp/pen/bWLwgP.css' })

if name == 'main': app.run_server(debug=True)

dash.exceptions.NonExistantPropException: Attempting to assign a callback with the property "filename" but the component "upload-data" doesn't have "filename" as a property.

Here is a list of the available properties in "upload-data": ['children', 'id', 'contents', 'accept', 'disabled', 'disable_click', 'max_size', 'min_size', 'multiple', 'className', 'className_active', 'className_reject', 'className_disabled', 'style', 'style_active', 'style_reject', 'style_disabled']

chriddyp commented 6 years ago

@alexbeo I'm sorry, I don't follow. What is the issue?

alexbeo commented 6 years ago

The code from the example that worked before does not work.

alexbeo commented 6 years ago

For some reason, the filename and last_modified element is missing in the list. Previously, such an error did not arise and everything worked.