The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

fitbitViz


The fitbitViz R package allows the extraction of data and the visualization of ‘ggplot2’, ‘Leaflet’ and 3-dimensionsal ‘Rayshader’ Maps using the Fitbit Web API. If you own any of the Fitbit activity trackers you can take advantage of this package. A detailed explanation of the functionality can be found both in the Vignette and in the blog post.

The 3-dimensional Rayshader Map requires the installation of the CopernicusDEM R package which includes the 30- and 90-meter elevation data.


Requirements:


To make use of this R package you have first to register an Application in https://dev.fitbit.com/. By registering an application you will receive the Fitbit token which besides your existing user-id is required so that you can take advantage of the fitbitViz functions.

There are many resources on the web on how to setup a Fitbit application. The Fitbit web API documenation includes more details. The next images and comments explain the whole process,


The parsed response looks as follows,


You now have your Access Token and can start using the fitbitViz R package to access and visualize your data. Keep in mind that the Access token is valid for 8 hours. Based on the documentation of the fitbit API

“After the Access Token expiration time has passed your requests will receive a 401 HTTP error. When this happens, your app should use the Refresh Token to get a new pair of tokens”.

To refresh the token the user of the fitbitViz R package can use the refresh_token_app() function, which requires the client id, client secret and refresh token of your registered Fitbit application, 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 token
new_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)


Keep track of your activities using ‘fitbitViz’, ‘Blogdown’ and ‘Github Actions’


UPDATE 26-12-2022: The registration of an Application of the fitbit web API has changed and it seems that users have to refresh the token every 8 hours. The following instructions were meant to be used with a registered application that wouldn’t require to refresh the token after 1 year.


The functions of the fitbitViz R package can be used in an automatic way so that the user can keep track of the Visualizations and data over time.

From the first moment I’ve started implementing the fitbitViz R package this is what I actually had in my mind. You can have a look to my Fitbit Visualizations website. The following steps explain in detail how this can be achieved:

What it remains is to modify the .github/workflows/gh_fitbit_blog.yaml file to adjust the

Regarding the fitbitViz parameters (.github/workflows/gh_fitbit_blog.yaml file) at it’s current state the application takes:


The order to modify, debug or include new code / functions to the files of this Github Repository is the following:


One important thing to keep in mind is that besides the Visualizations the user has access also to the pre-processed Fitbit data by clicking to a CSV button as shown in the next image,




Docker Image:


Docker images of the fitbitViz package are available to download from my dockerhub account. The images come with Rstudio and the R-development version (latest) installed. The whole process was tested on Ubuntu 18.04. To pull & run the image do the following,



docker pull mlampros/fitbitviz:rstudiodev

docker run -d --name rstudio_dev -e USER=rstudio -e PASSWORD=give_here_your_password --rm -p 8787:8787 mlampros/fitbitviz:rstudiodev


The user can also bind a home directory / folder to the image to use its files by specifying the -v command,



docker run -d --name rstudio_dev -e USER=rstudio -e PASSWORD=give_here_your_password --rm -p 8787:8787 -v /home/YOUR_DIR:/home/rstudio/YOUR_DIR mlampros/fitbitviz:rstudiodev


In the latter case you might have first give permission privileges for write access to YOUR_DIR directory (not necessarily) using,



chmod -R 777 /home/YOUR_DIR


The USER defaults to rstudio but you have to give your PASSWORD of preference (see www.rocker-project.org for more information).


Open your web-browser and depending where the docker image was build / run give,


1st. Option on your personal computer,


http://0.0.0.0:8787 


2nd. Option on a cloud instance,


http://Public DNS:8787


to access the Rstudio console in order to give your username and password.


Package Installation & Citation:


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 the fitbitViz R package in your paper or research please cite https://CRAN.R-project.org/package=fitbitViz:


@Manual{,
  title = {{fitbitViz}: Fitbit Visualizations},
  author = {Lampros Mouselimis},
  year = {2022},
  note = {R package version 1.0.6},
  url = {https://CRAN.R-project.org/package=fitbitViz},
}


These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.