title: Using dash upload component to upload csv file and generate a graph
body: <p>I want to upload a csv file and generate a graph that outputs the data from the csv file, I am able to upload the csv and display the data using dash_table, but I am unable to get the graph to work.
  My error after uploading the csv file: Invalid argument <code>figure.data</code> passed into Graph with ID &quot;Mygraph&quot;.
  Expected an array.
  Was supplied type <code>object</code>.</p>
  <pre><code>import base64
  import datetime
  import io
  import plotly.graph_objs as go
  import cufflinks as cf
  
  import dash
  from dash.dependencies import Input, Output, State
  import dash_core_components as dcc
  import dash_html_components as html
  import dash_table
  
  import pandas as pd
  
  external_stylesheets = [&quot;https://codepen.io/chriddyp/pen/bWLwgP.css&quot;]
  
  app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
  server = app.server
  
  colors = {&quot;graphBackground&quot;: &quot;#F5F5F5&quot;, &quot;background&quot;: &quot;#ffffff&quot;, &quot;text&quot;: &quot;#000000&quot;}
  
  app.layout = html.Div(
      [
          dcc.Upload(
              id=&quot;upload-data&quot;,
              children=html.Div([&quot;Drag and Drop or &quot;, html.A(&quot;Select Files&quot;)]),
              style={
                  &quot;width&quot;: &quot;100%&quot;,
                  &quot;height&quot;: &quot;60px&quot;,
                  &quot;lineHeight&quot;: &quot;60px&quot;,
                  &quot;borderWidth&quot;: &quot;1px&quot;,
                  &quot;borderStyle&quot;: &quot;dashed&quot;,
                  &quot;borderRadius&quot;: &quot;5px&quot;,
                  &quot;textAlign&quot;: &quot;center&quot;,
                  &quot;margin&quot;: &quot;10px&quot;,
              },
              # Allow multiple files to be uploaded
              multiple=True,
          ),
          dcc.Graph(id=&quot;Mygraph&quot;),
          html.Div(id=&quot;output-data-upload&quot;),
      ]
  )
  
  
  @app.callback(
      Output(&quot;Mygraph&quot;, &quot;figure&quot;),
      [Input(&quot;upload-data&quot;, &quot;contents&quot;), Input(&quot;upload-data&quot;, &quot;filename&quot;)],
  )
  def update_graph(contents, filename):
      fig = {
          &quot;layout&quot;: go.Layout(
              plot_bgcolor=colors[&quot;graphBackground&quot;],
              paper_bgcolor=colors[&quot;graphBackground&quot;],
          )
      }
  
      if contents:
          contents = contents[0]
          filename = filename[0]
          df = parse_data(contents, filename)
          df = df.set_index(df.columns[0])
          fig[&quot;data&quot;] = df.iplot(
              asFigure=True, kind=&quot;scatter&quot;, mode=&quot;lines+markers&quot;, size=1
          )
  
      return fig
  
  
  def parse_data(contents, filename):
      content_type, content_string = contents.split(&quot;,&quot;)
  
      decoded = base64.b64decode(content_string)
      try:
          if &quot;csv&quot; in filename:
              # Assume that the user uploaded a CSV or TXT file
              df = pd.read_csv(io.StringIO(decoded.decode(&quot;utf-8&quot;)))
          elif &quot;xls&quot; in filename:
              # Assume that the user uploaded an excel file
              df = pd.read_excel(io.BytesIO(decoded))
          elif &quot;txt&quot; or &quot;tsv&quot; in filename:
              # Assume that the user upl, delimiter = r'\s+'oaded an excel file
              df = pd.read_csv(io.StringIO(decoded.decode(&quot;utf-8&quot;)), delimiter=r&quot;\s+&quot;)
      except Exception as e:
          print(e)
          return html.Div([&quot;There was an error processing this file.&quot;])
  
      return df
  
  
  @app.callback(
      Output(&quot;output-data-upload&quot;, &quot;children&quot;),
      [Input(&quot;upload-data&quot;, &quot;contents&quot;), Input(&quot;upload-data&quot;, &quot;filename&quot;)],
  )
  
  
  def update_table(contents, filename):
      table = html.Div()
  
      if contents:
          contents = contents[0]
          filename = filename[0]
          df = parse_data(contents, filename)
  
          table = html.Div(
              [
                  html.H5(filename),
                  dash_table.DataTable(
                      data=df.to_dict(&quot;rows&quot;),
                      columns=[{&quot;name&quot;: i, &quot;id&quot;: i} for i in df.columns],
                  ),
                  html.Hr(),
                  html.Div(&quot;Raw Content&quot;),
                  html.Pre(
                      contents[0:200] + &quot;...&quot;,
                      style={&quot;whiteSpace&quot;: &quot;pre-wrap&quot;, &quot;wordBreak&quot;: &quot;break-all&quot;},
                  ),
              ]
          )
  
      return table
  
  
  if __name__ == &quot;__main__&quot;:
      app.run_server(debug=True)
  </code></pre>
  <p><strong>Error:</strong>
  <a href="https://i.stack.imgur.com/CEnsz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CEnsz.png" alt="screenshot of error" /></a></p>