From csv table to tinydb

Hello everyone, I would like to populate a tinydb from a local csv table, I did some research without finding something that works

Hello Patel

Much depends on how you want to store the data - a row as one record, each individual cell as 1 record or what?

Hi Chris, my goal is starting from a csv like this:
tag1,data1
tag2,data2
......
but I can also start from 2 csv like:
csv1 : tag1,tag2,tag2
csv2 : data1,data2,data3

This is preferable for your csv format, because it more robustly keeps tags and their values together, and fits well with spreadsheet programs for data display and update.

Your TinyDB sounds very simple, with no list values for any tags.
Is that true?

that is true, only one value for a tag

How do you plan to supply the csv file to the app?

  • package it into the Media folder at build time?
  • download it from a Google Sheet at run time?
  • load it from an SD card?
  • scrape it from a web page?

into the Media folder at build time

read your csv file on first run of your app using the file component, convert the csv table into a list of lists using the list from csv table block and store the list of lists in only one tag in TinyDB... later you can use the lookup in pairs block to lookup your tags...
How does the lookup in pairs block work?
Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

[quote="Taifun, post:8, topic:15615"]
list of lists
[/quote]Tank You for suggestions, I stopped here, I don't know how to go on

DB

to understand what I said earlier

you first have to learn the basics...

A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook http://www.appinventor.org/book2 ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.
There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro and the aia files for the projects in the book are here: http://www.appinventor.org/bookFiles
How to do a lot of basic things with App Inventor are described here: http://www.appinventor.org/content/howDoYou/eventHandling .

Also do the tutorials Our Tutorials! to learn the basics of App Inventor, then try something and follow the Top 5 Tips: How to learn App Inventor

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

You said list of lists, but I can not find this kind of variable, Do I need ListPicker ?

...... there are two factors that determine how the data should be stored

  1. How the CSV file is arranged - multiple rows and columns? One col for data description/title, second col for data, or what exactly?

  2. How is the App going to use the data - selection of specific data identified by description/title (= TinyDb tag), Display data as a List or Table, or what exactly?

blocks

as already said, to first learn the basics would help you a lot...

Taifun

i'm trying with 2 csv like
csvtag :tag1,tag2,tag3
csvdata:data1,data2,data3
without success

Try like this:

you may need to swap out "list from csv table" with "list from csv row"

i'm trying with 2 csv like
csvtag :tag1,tag2,tag3
csvdata:data1,data2,data3
without success

Patel

I would not recommend using two .csv files. The tags are directly related to the data - to avoid mistakes in the files, better to use one file.

The info above is not enough in response to my questions!

  1. Can you upload an actual CSV file that represents the real data you wish to import.

  2. Can you please carefully describe what the App is going to do with the data, as that affects how it should be stored.

my csv would be:
tag1,data1
tag2,data2
tag3,data3
when tinydb populated I type the tag in textbox then press button to have data value.
The next goal is 3 buttons with the tags, when I tap a button I have the value in the label

Hi TIMAI2, thanks for your help, the following blocs run well, how can I use only one csv ?

Assumptions

  1. csv is in table format
tag1,data1
tag2,data2
tag3,data3
  1. That you may want to edit the data once loaded, so only load the csv on the first run of the app.

I have not tested either of these......

Two versions:

a) As before, each element from the csv is loaded to a tag

b) The csv data is loaded to a list, then the entire list is saved to a single tag

Now, you have previously been pointed at documentation on lists:

Hi TIMAI2, many thanks for your help, I tested the two version, the first is OK, I understood how it works and modified it for my needs, the second one is too complicated for me beginner.
SOLVED