ThefitbitViz R package allows the extraction ofdata and the visualization of‘ggplot2’,‘Leaflet’ and3-dimensionsal ‘Rayshader’ Maps using theFitbit WebAPI. If you own any of theFitbit activity trackersyou can take advantage of this package. A detailed explanation of thefunctionality can be found both in the Vignette and in theblogpost.
The 3-dimensional Rayshader Map requires the installation of theCopernicusDEM Rpackage which includes the30- and 90-meter elevationdata.
To make use of this R package you have first toregister anApplication inhttps://dev.fitbit.com/. By registering an applicationyou will receive the Fitbittoken which besides yourexistinguser-idis required so that you can take advantage of thefitbitViz functions.
There are many resources on the web on how to setup a Fitbitapplication. TheFitbit web APIdocumenation includes more details. The next images and commentsexplain the whole process,
Go tohttps://dev.fitbit.com/ and click onManage >Register an App
Login with your Fitbit credentials and follow theprompts. I used as URL in the Registration Pagemy Fitbituser-id url,https://www.fitbit.com/user/USER_ID. Youhave to replace theUSER_ID in the url withyourspecific user-id. Then in theRedirect URL fieldusehttps://localhost. Tick the remainingoptions as in the next image,read and agree to the terms ofservice and clickRegister to register theapplication.

Once the app is created, click on the ‘OAuth 2.0 Tutorial’weblink near the bottom of the screen:

In the ‘Fitbit OAuth 2.0 Tutorial’ website theClientID already exists and we have to copy-paste theClientSecret from the previous web page

then we scroll down to the ‘Getting an Access Token’ section andclick to the two “Generate” buttons to generate the required codes,

In the next section ‘Step 2: Display Authorization Page’ we clickto the already created URL which will open a new tab to our webbrowser,

in this new web page tick theAllow All andclick theAllow button

After clickingAllow, the browser tab redirects to thecallback URL. Although this might seem like an “Unable to connect” webpage the important thing here is to just copy the URL of the web page asfollows,

and paste it to the section “Step 3: Handle the Redirect” wherethe “Authorization code” and “State” will be created,

finally in section “Step 4: Get Tokens” we just click to theSUBMIT REQUEST button to receive the token in theResponse field,

Theparsed response looks as follows,

You now have yourAccess Token and can start usingthefitbitViz R package to access and visualize yourdata. Keep in mind that theAccess token isvalid for 8hours. Based on the documentation of the fitbit API
“After the Access Token expiration time has passed your requestswill receive a 401 HTTP error. When this happens, your app should usethe Refresh Token to get a new pair of tokens”.
To refresh the token the user of thefitbitViz R package canuse therefresh_token_app() function, whichrequires theclient id,client secretandrefresh token of your registered Fitbitapplication, in the following way:
require(fitbitViz)#..............................................# Refresh token once it expires (after 8 hours)#..............................................client_id='xxxxxx'client_secret='xxxxxxxxxxxxxxxxxx'refresh_token='xxxxxxxxxxxxxxxxxxxxxxxx'# refresh the tokennew_token=refresh_token_app(client_id = client_id,client_secret = client_secret,refresh_token = refresh_token)# a named list that includes the new 'access_token' and 'refresh_token'str(new_token)UPDATE 26-12-2022: The registration of anApplication of thefitbit web API has changed and it seems thatusers have to refresh the token every8 hours. Thefollowing instructions were meant to be used with a registeredapplication that wouldn’t require to refresh the token after1year.
The functions of thefitbitViz R package can be usedin an automatic way so that the user can keep track of theVisualizations anddata over time.
From the first moment I’ve started implementing thefitbitViz R package this is what I actually had in mymind. You can have a look tomy FitbitVisualizations website. The following steps explain in detail howthis can be achieved:
What it remains is to modify the.github/workflows/gh_fitbit_blog.yamlfile to adjust the


Regarding thefitbitViz parameters (.github/workflows/gh_fitbit_blog.yamlfile) at it’s current state the application takes:
The order tomodify,debug orinclude new code/ functions to the files of this Github Repository is thefollowing:
Oneimportant thing to keep in mind is that besidesthe Visualizations the user has access also to the pre-processed Fitbitdata by clicking to aCSV button as shown in the nextimage,

Docker images of thefitbitViz package areavailable to download from mydockerhubaccount. The images come withRstudio and theR-development version (latest) installed. The whole process wastested on Ubuntu 18.04. Topull &run the image do the following,
docker pull mlampros/fitbitviz:rstudiodevdocker run-d--name rstudio_dev-e USER=rstudio-e PASSWORD=give_here_your_password--rm-p8787:8787 mlampros/fitbitviz:rstudiodevThe user can alsobind a home directory / folder tothe image to use its files by specifying the-vcommand,
docker run-d--name rstudio_dev-e USER=rstudio-e PASSWORD=give_here_your_password--rm-p8787:8787-v/home/YOUR_DIR:/home/rstudio/YOUR_DIR mlampros/fitbitviz:rstudiodevIn the latter case you might have first give permission privilegesfor write access toYOUR_DIR directory (notnecessarily) using,
chmod-R777/home/YOUR_DIRTheUSER defaults torstudio but you haveto give yourPASSWORD of preference (seewww.rocker-project.org for moreinformation).
Open your web-browser and depending where the docker image wasbuild / run give,
1st. Option on your personal computer,
http://0.0.0.0:87872nd. Option on a cloud instance,
http://Public DNS:8787to access the Rstudio console in order to give your username andpassword.
To install the package from CRAN use,
install.packages("fitbitViz")and to download the latest version of the package from Github,
remotes::install_github('mlampros/fitbitViz')If you use thefitbitViz R package in your paper orresearch please citehttps://CRAN.R-project.org/package=fitbitViz:
@Manual{, title= {{fitbitViz}: Fitbit Visualizations}, author= {Lampros Mouselimis}, year= {2022}, note= {R package version1.0.7}, url= {https://CRAN.R-project.org/package=fitbitViz},}