'Upload a grid to your Plotly account with the specified filename.
Positional arguments:
- grid: A plotly.grid_objs.Grid object,
call `help(plotly.grid_ops.Grid)` for more info.
- filename: Name of the grid to be saved in your Plotly account.
To save a grid in a folder in your Plotly account,
separate specify a filename with folders and filename
separated by backslashes (`/`).
If a grid, plot, or folder already exists with the same
filename, a `plotly.exceptions.RequestError` will be
thrown with status_code 409
Optional keyword arguments:
- world_readable (default=True): make this grid publically (True)
or privately (False) viewable.
- auto_open (default=True): Automatically open this grid in
the browser (True)
- meta (default=None): Optional Metadata to associate with
this grid.
Metadata is any arbitrary
JSON-encodable object, for example:
`{"experiment name": "GaAs"}`
Filenames must be unique. To overwrite a grid with the same filename,
you\'ll first have to delete the grid with the blocking name. See
`plotly.plotly.grid_ops.delete`.
Usage example 1: Upload a plotly grid
from plotly.grid_objs import Grid, Column
import plotly.plotly as py
column_1 = Column([1, 2, 3], \'time\')
column_2 = Column([4, 2, 5], \'voltage\')
grid = Grid([column_1, column_2])
py.grid_ops.upload(grid, \'time vs voltage\')
Usage example 2: Make a graph based with data that is sourced
from a newly uploaded Plotly grid
import plotly.plotly as py
from plotly.grid_objs import Grid, Column
from plotly.graph_objs import Scatter
# Upload a grid
column_1 = Column([1, 2, 3], \'time\')
column_2 = Column([4, 2, 5], \'voltage\')
grid = Grid([column_1, column_2])
py.grid_ops.upload(grid, \'time vs voltage\')
# Build a Plotly graph object sourced from the
# grid\'s columns
trace = Scatter(xsrc=grid[0], ysrc=grid[1])
py.plot([trace], filename=\'graph from grid\')'

@classmethod
def upload(cls, grid, filename, world_readable=True, auto_open=True, meta=None):

    if (filename[(-1)] == '/'):
        filename = filename[0:(-1)]
    paths = filename.split('/')
    parent_path = '/'.join(paths[0:(-1)])
    filename = paths[(-1)]
    if (parent_path != ''):
        file_ops.mkdirs(parent_path)
    grid_json = grid._to_plotly_grid_json()
    if (meta is not None):
        grid_json['metadata'] = meta
    payload = {'filename': filename, 'data': grid_json, 'world_readable': world_readable}
    if (parent_path != ''):
        payload['parent_path'] = parent_path
    response = v2.grids.create(payload)
    parsed_content = response.json()
    cols = parsed_content['file']['cols']
    fid = parsed_content['file']['fid']
    web_url = parsed_content['file']['web_url']
    cls._fill_in_response_column_ids(grid, cols, fid)
    grid.id = fid
    if (meta is not None):
        meta_ops.upload(meta, grid=grid)
    if auto_open:
        _open_url(web_url)
    return web_url
