A set of tools that allow for interactive visualization of input-output tables.
The purpose of this project is to provide an interactive web visualization for input-output tables using R and PostgreSQL. As of right now there are two components, an R Shiny web application and a PostgreSQL Database (more specifically a PostGIS one). The network of those two components can be created with one single docker-compose
command.
In order to run the app, you need the following tools installed:
To install Docker and Docker Compose (comes already installed with Docker Desktop) for you system follow the links below:
You only need git installed if you want to contribute to the repository or clone it without having to download it manually.
You only need R (version 3.5 or higher) and RStudio installed in case you would like to make your own changes to the app and try them out before you create the docker containers.
If you are on a Linux machine, you need to install the following packages via apt
(or any other package manager) as they are required by the R packages needed:
sudo apt install libpq-dev libssl-dev libxml2-dev libcurl4-openssl-dev
The command to install the R packages can be found on the respective file you want to edit.
To get the app, you can either
git clone https://github.com/fineprint-global/io-visualization.git
There are a few settings that you have to make before you can run the app.
.env
file in the root directoryYou have to set the following variables, here is an example .env
file:
POSTGRES_PASSWORD=postgresuserpassword
POSTGRES_PORT=5454
SHINY_PORT=80
.Renviron
file in the /app
directoryIn the .Renviron
file, you need to set the internal container port (which is the 5432
) as your db_port
, so DO NOT match the POSTGRES_PORT
you set in the .env
file, but set the default port for postgres, which is 5432
. Here is an example file that needs to be created inside the /app
directory. Only if you would run the app in a separate docker-network then you would need to use the POSTGRES_PORT
you set.
db_host=ioviz_db
db_port=5432
db_name=fabio
db_user=app
db_password=appuserpassword
There are three ways to run this app.
io-visualization
) with a shell of your choice and run the following command:
docker-compose up -d
Now both, the ioviz_app
(RShiny app) and the ioviz_db
(PostGIS database) should be running on ports specified in the docker-compose.yml
on your localhost (e.g. ports 80
and 5454
respectively, although ioviz_app
will communicate with ioviz_db
at port 5432
in their internal docker-network). To verify that both containers are running and the ports are correct, you can run docker-compose ps
(in the root directory) or docker ps
(anywhere).
You should now be able to see the app running at localhost:80 or – if not 80
– at the port you specified in SHINY_PORT
.
If there are any problems, check out the troubleshooting section.
You will have to adjust the main.R
located in the input-output-to-db directory to load your own input-output table and adjust it to the proper database format.
In order for your input-output table to be used with the Shiny app, you first need to adjust it to the database format used for this application.
The database format can be found in the db folder in both .dbm
format (to be viewed and edited via the open source data modelling software pgModeler) and .png
format.
Please care, the input-output
table in the database is the Leontief Inverse of the input-output table.
Check out the main.R
file to see how FABIO
was modified from big matrices in .rds
files to fit the database format.
The folders to take care of are the app folder and the docker-rshiny folder. The app
folder will be used to change the visualizations whereas the docker-rshiny
folder needs to be kept in mind for any new packages you might require.
app
folderBefore you dive into this, if you are new to RShiny, you may want to check out this tutorial.
In our example, the app
folder is divided into 3 main files:
global.R
: this will be executed once for every worker process, not for every user, so this is where you specify database connections and perform other setup-related tasksui.R
: you specify the user interface here. output
elements (e.g. plotlyOutput()
) are defined here and respective render
functions (e.g. renderPlotly({ ... })
) for those are performed in the server.R
. If you want to add new visualizations or other elements, define them here.server.R
: any new visualizations defined in the ui.R
should be implemented in the server.R
, this is where you collect your data, bring it into the correct format and then define the output (e.g. for plotly
).docker-rshiny
folder for packagesYou need to edit the Dockerfile if you add any new packages that are not included yet.
As an example, in this part of the Dockerfile …
...
# Install a few dependencies for packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
&& install2.r --error \
plotly \
RPostgreSQL \
pool \
RColorBrewer \
shinythemes \
shinycssloaders \
viridis
...
... you could edit it to include leaflet
to add map functionalities:
...
viridis \
leaflet
...
io-visualization
directory and run docker-compose restart
docker-compose stop
docker-compose up
, run docker-compose down
docker-rshiny/
for any packages necessary for the app to run.If the notes above or the section below do not help, please create an issue.
In case there are issues with building and running the R Shiny Docker from the directory (especially in Windows, file permissions tend to get messed up, and then the container is constantly restarting, sometimes with the error: standard_init_linux.go:207: exec user process caused "no such file or directory"
), you can alternatively use the docker image from Docker Hub. For this, you need to replace the build context with the Docker Hub image like below:
# build:
# context: ./docker-rshiny
image: fineprint/ioviz-rshiny
This project has received funding from the European Research Council (ERC) under the European Union's Horizon 2020 research and innovation programme (grant agreement No. 725525).