# loadTable from object and not from url

**URL:** <https://discourse.processing.org/t/loadtable-from-object-and-not-from-url/21788>\
**Category:** Coding Questions\
**Created:** [June 11, 2020, 7:58pm UTC](https://discourse.processing.org/t/loadtable-from-object-and-not-from-url/21788 "2020-06-11T19:58:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![suvir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/suvir/32/9357_2.png) [@suvir](https://discourse.processing.org/u/suvir)\
**Post date:** [June 11, 2020, 7:58pm UTC](https://discourse.processing.org/t/loadtable-from-object-and-not-from-url/21788/1 "2020-06-11T19:58:31Z")

</div>

Hi,

This is what i was doing before.

```auto
p.preload = () => {
    data = (p as any).loadTable("http://127.0.0.1:3448/sample.csv", "csv", "header");
  };

```

I would like to intiliaze the data above from a js response object. The object has the same csv content.  
My question is how to initialize a p5 table from an object consisting of csv content as string.

---

<div class="post-metadata">

**Author:** ![Sven](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sven/32/8293_2.png) [@Sven](https://discourse.processing.org/u/Sven)\
**Post date:** [June 11, 2020, 10:04pm UTC](https://discourse.processing.org/t/loadtable-from-object-and-not-from-url/21788/2 "2020-06-11T22:04:02Z")

</div>

Hello!

Theres no shortcut to accomplish that, I’m afraid. You’ll have to build the table row for row using [p5.TableRow](https://p5js.org/reference/#/p5.TableRow).

---

<div class="post-metadata">

**Author:** ![suvir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/suvir/32/9357_2.png) [@suvir](https://discourse.processing.org/u/suvir)\
**Post date:** [June 12, 2020, 6:37am UTC](https://discourse.processing.org/t/loadtable-from-object-and-not-from-url/21788/3 "2020-06-12T06:37:10Z")

</div>

> [@Sven](#):
>
> [p5.TableRow](https://p5js.org/reference/#/p5.TableRow)

hmm…i have like 23437 rows actually. That’s going to be expensive operation.

---

<div class="post-metadata">

**Author:** ![Sven](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sven/32/8293_2.png) [@Sven](https://discourse.processing.org/u/Sven)\
**Post date:** [June 12, 2020, 7:16am UTC](https://discourse.processing.org/t/loadtable-from-object-and-not-from-url/21788/4 "2020-06-12T07:16:34Z")

</div>

Well, that’s what happens behind the scenes anyway. If there was a p5.js function to which you could pass CSV content as a string, that function would still have to break the string apart and build a `p5.Table` from those parts. It wouldn’t be a less expensive operation just because another programmer implemented the function for you.

I wouldn’t worry too much before you actually try it, though. Maybe it will go faster then you expect, and you only have to do it once at the beginning of your sketch, during `setup`.

Just because I’m curious, what’s the reason you can’t have the CSV in a file and use the built-in `loadTable` function?

---

<div class="post-metadata">

**Author:** ![suvir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/suvir/32/9357_2.png) [@suvir](https://discourse.processing.org/u/suvir)\
**Post date:** [June 12, 2020, 7:18am UTC](https://discourse.processing.org/t/loadtable-from-object-and-not-from-url/21788/5 "2020-06-12T07:18:57Z")

</div>

> [@Sven](#):
>
> Just because I’m curious, what’s the reason you can’t have the CSV in a file and use the built-in `loadTable` function?

I have it originally in a file, but then i use swagger UI to make a get api call and i get the data in response.

---

<div class="post-metadata">

**Author:** ![Sven](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sven/32/8293_2.png) [@Sven](https://discourse.processing.org/u/Sven)\
**Post date:** [June 12, 2020, 7:38am UTC](https://discourse.processing.org/t/loadtable-from-object-and-not-from-url/21788/6 "2020-06-12T07:38:10Z")

</div>

Hmm, interesting. How are you making the GET API call, could you share the code?

---

<div class="post-metadata">

**Author:** ![suvir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/suvir/32/9357_2.png) [@suvir](https://discourse.processing.org/u/suvir)\
**Post date:** [June 13, 2020, 10:27am UTC](https://discourse.processing.org/t/loadtable-from-object-and-not-from-url/21788/7 "2020-06-13T10:27:27Z")

</div>

Here you go,

> **[swagger-ui-react - CodeSandbox](https://codesandbox.io/s/swagger-ui-react-oj1rh?file=%2Fsrc%2Findex.tsx)**
>
> swagger-ui-react

Interesting line to see is

```auto
      <P5Wrapper sketch={sketch} data={data} />

```

and you to get the csv file from url, type less-xy.csv.

In short, what i am trying to accomplish in that code sandbox is, fetch a csv file using swagger and then display its content using p5-js. As you can see in the code, right now, i have hard coded the url in p5.js, so we are actually fetch file twice, once from swagger and one done by p.preload…I want to load the data dynamically in p5.js.
