How can I use R Shiny to update a column in a csv? (Pokemon catch 'em all)

Hi everyone,

Here is an example use case:

There is a list_of_known_pokemon.csv maintained somewhere on the internet. It has columns "pokemon_id", and associated characteristics such as "name", "weight", "height" and "class". This list expands as more pokemons are discovered daily.

We want to create a Shiny app that will display this table. We also want the users of the shiny app to be able to indicate that we have caught a pokemon and on which date it was caught.

How should we proceed?

My current thought process would be to maintain a "data/list_of_caught_pokemons.csv" file on the shiny repo. It would have two colums: "pokemon_id" and "date_caught". If we have caught 7 pokemons so far then the file would have 7 rows.

In the shiny app, we display the result of
list_of_known_pokemon %>% left_join(list_of_caught_pokemons)

The shiny user would edit the "date_caught" column in the shiny (HOW?) to indicate a new pokemon has been caught, then press a button that would "export an updated version of 'list_of_caught_pokemons.csv', and commit it to the shiny repo"

I think that would work, but I'm afraid we might run into issues when 2+ users are using the app at the same time.

Any ideas would be greatly appreciated.

Trying to use a csv file as a database is impractical, a file can't manage concurrency and keep data consistency.

I would strongly recommend the use of a RDBMS or any other type of database, it could be as simple as using SQLite.

I agree. I'll push for database access.

Guess I'll just need to find a shiny example where you insert/remove rows from a DB.

Just to clarify, that documentation is for shiny-server, not for specifically, the MySQL service is not running on your app's container on so you would need to host it elsewhere.

In case you want to try, has a free tier of "Postgresql as a service".

1 Like

Here you can find all you need to get you started

1 Like

Thanks, I've got some reading to do :slight_smile:

I'm pretty clear on the db commands. ElephantSQL is new to me and awesome.

What I'm not clear on how to implement is how I could display the table in a way that the date_caught column is editable (and that an edit triggers writing to the list_of_caught_pokemons in the DB).

list_of_known_pokemon %>% left_join(list_of_caught_pokemons)

There are many options, among them you could use this package for allowing manual editing of the table

Although, you need to trigger the update by other means like a "save" button for example.

1 Like

thanks mate,
Really improved the architecture of the project today :slight_smile:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.