← Data apps

Data apps: cards

One card for each data idea you'll use in App Builder, to look up while you build. Each says what it's for, how to do it, and links to the lesson that teaches it.

Lists that must agree

Lists that must agree

Two lists can describe the same things when item 1 of one goes with item 1 of the other. Their place number is the only link.

  1. Add to the end of every list in the same event.
  2. Remove the same item number (such as ClickedIndex) from every list.
  3. If the lists need sorting or more details, use a table instead.

Watch for: While the app runs, the number of items in each list shows on the left: they should always match.

App Builder
Lists are under Lists (whole app). A List object shows one list.

Other apps work the same way; look for the same word in the menus. Lesson: Two lists that must agree

Tables and records

Make a table

A table keeps records: one row per thing, one field (column) per detail. Every row has the same fields.

  1. Under Tables on the left, type a name and press +.
  2. Click a field's name to rename it, change its type (Text or Number), move or delete it.
  3. Press + after the field names to add a field, and + Row to add a row. Tab moves along.

Watch for: { } JSON shows the table as a list of records, the way JavaScript and Python keep it.

App Builder
Tables need Level 4 (a lesson sets the level for you).

Other apps work the same way; look for the same word in the menus. Lesson: One table instead

Show a table on the screen

A Table object shows a table by itself: a column for each field, a row for each record.

  1. Add a Table object (Data).
  2. In Properties, set Shows table, and choose the columns to show.
  3. An item in ... is clicked runs when a row is clicked: ClickedIndex is its number, ClickedItem the row.
App Builder
Table is under Data in + Add object (Level 4). Columns to show can hide a field on screen; the table still keeps it.

Other apps work the same way; look for the same word in the menus. Lesson: One table instead

Add, change and remove rows

Rows change as a whole: a new song arrives with all its fields, and a removed song takes them all with it.

  1. Tables, Add a row: one box for each field, such as TitleInput.text.
  2. Tables, Set a field of row N: change one detail of one row.
  3. Tables, Remove row N, or Clear table.

Watch for: A number field won't take text that isn't a number: int(Box.text) turns typed text into a number.

App Builder
Add a row's boxes follow the table's fields: add or rename a field and the boxes change too.

Other apps work the same way; look for the same word in the menus. Lesson: One table instead

Read a field: a dot

A row is a record; a dot and a field name read one detail of it.

  1. item(Songs, 2).artist is the artist of row 2.
  2. ClickedItem.title is the title of the clicked row.
  3. Inside For each row, LoopItem.length is this row's length.
App Builder
A variable can hold a whole row: Set variable best to item(Songs, 1), then best.title.

Other apps work the same way; look for the same word in the menus. Lesson: Records and fields

Total or best so far: For each row

For each row in table runs a sub-event once per row. A running total adds each row's value; a best so far keeps the row that beats the rest.

  1. On the event: start the total at 0 (or the best at item(Table, 1)).
  2. Sub-event: For each row in table, then add LoopItem.field (or a Compare and Set variable best to LoopItem).
  3. A sub-event after it, with no condition, shows the answer.

Watch for: Starting the total inside the loop wipes it every row.

App Builder
Add a sub-event from the event's ⋯ menu. A sub-event with no condition always runs.

Other apps work the same way; look for the same word in the menus. Lesson: Records and fields

Saving between visits

Remember between visits

A remembered variable, list or table is still there when the app is opened again, in this browser.

  1. Click the 💾 beside it on the left so it lights up.
  2. Test a return visit with Restart, and a first visit with Forget saved data.
  3. count(Table) = 0 when the screen starts tells a first visit from a return visit.

Watch for: It's kept in this browser only: not in the project file you Save, and not on other computers.

App Builder
Level 3 and up. Each lesson step keeps its own remembered values.

Other apps work the same way; look for the same word in the menus. Lesson: Saving between visits

Search

Sort a table

Sort puts whole rows in order by one field, so every row keeps its details.

  1. Tables, Sort table ... by a field.
  2. A to Z, smallest first; or Z to A, biggest first.

Watch for: A number field sorts by size. Numbers kept as text sort character by character: 10 before 9.

App Builder
Sort ignores capitals and keeps rows with the same value in the order they were.

Other apps work the same way; look for the same word in the menus. Lesson: Search, filter and sort

Search or filter

Go through every row and copy the ones that match into a second table. The original table stays whole.

  1. On the event: Clear table Results.
  2. Sub-event: For each row in table, and a Compare test, such as contains(lower(LoopItem.title), lower(Search.text)) = true.
  3. Its action: Add a row to table Results, each field from LoopItem.

Watch for: Never remove the rows that don't match from the original table: they'd be gone for good.

App Builder
lower(...) makes capitals not matter. Find expressions lists contains() and lower().

Other apps work the same way; look for the same word in the menus. Lesson: Search, filter and sort

Play a sound

A Sound object plays music or a sound effect when an event says so, or when the user presses its own button.

  1. Add a Sound object (Media) and choose its sound in Properties. Listen plays it there.
  2. Actions: Play, Stop, Set sound to. Conditions: is playing, finishes playing.
  3. To play a row's own sound, give the table a sound field and use Set sound to the one named ClickedItem.sound.

Watch for: A browser plays sound only after the user has clicked or pressed something in the app.

App Builder
The built-in sounds are made for App Builder and free to use. + Upload sound adds your own (under about 5 MB).

Other apps work the same way; look for the same word in the menus. Lesson: Search, filter and sort

Final challenge: your own data app

Bring in data from a spreadsheet

Records you already have in a spreadsheet can go straight into a table, instead of being typed again.

  1. Make the table and its fields first, in the same order as the spreadsheet's columns.
  2. Copy the rows in the spreadsheet.
  3. Paste into the table's first cell, or press Paste rows under the table and paste there.

Watch for: A first row of field names is skipped. If a number field gets text, nothing is pasted and App Builder says which row.

App Builder
Pasting into a cell fills from that cell, adding rows as needed. Paste rows adds after the last row.

Other apps work the same way; look for the same word in the menus. Lesson: Challenge: your own data app

Show a video

A Video object plays a video from a link. Videos are linked, never uploaded.

  1. Find a video on Wikimedia Commons, open its page and copy the address.
  2. Add a Video object (Media) and paste the address into Video link in Properties.
  3. Play and Stop work as for a Sound. Set video to can take a link from a table field.

Watch for: Commons pages say who made each video and its licence: the player links to that page, so keep the credit.

App Builder
YouTube links stay off unless Allow YouTube links is ticked, which is your school's call.

Other apps work the same way; look for the same word in the menus. Lesson: Challenge: your own data app

Linked tables

Two tables that link

Two kinds of record go in two flat tables, linked by a value they share, such as each song's playlist.

  1. In the second table, open a field's menu and choose Links to (the first table). Its cells become a dropdown of the first table's first field.
  2. To show the matches: Clear, For each row, Compare the linked field with the chosen value, Add a row.
  3. To see it nested, open { } JSON under the first table and choose the grouped view. It's read only.

Watch for: Renaming a value in the tables on the left updates the rows that link to it. An event that renames it while the app runs doesn't, so the link breaks.

App Builder
A link that matches no row shows as missing. Deleting the first table turns the linked field back into plain text.

Other apps work the same way; look for the same word in the menus. Lesson: Two tables that link