Starting from:

$30

STAT240 Lab 7 Solved

Question 1: Interactive data visualization
Shiny Apps are interactive websites that provide functionality in R such as data visualization, data transfer, and data manipulation. They can be used to create interactive reports, or to prototype project or startup ideas. Shiny Apps can be deployed on public websites, or locally in R Studio sessions. Please follow this tutorial for an example of getting a Shiny App set up locally in an R Studio session: https://shiny.rstudio.com/tutorial/ written-tutorial/lesson1/.

a) SFU hosts a Shiny App server where you can upload code, and get it to run over the internet. When you run an SFU hosted Shiny App, it will be accessible in a website of this form: https:

//shiny.rcg.sfu.ca/u/username/myapp. Here, username is your Compute ID, and myapp is the name of your Shiny App. Shiny Apps are mainly specified by two files: server.R and ui.R. These files must reside in a directory, and the directory name that they reside in specifies the name of the Shiny App. The Shiny App included in this assignment (in the subdirectory myapp of the archive containing this assignment) provides visualizations of the iris dataset as density plots. In the App, there is a drop down menu where you may select a variable in the iris dataset, and then a density plot of that variable is provided.

Deploy this App on SFU’s Shiny App server by following these steps: https://www.rcg.sfu.ca/services/shiny/index.html. Note that you will have to use SFU’s VPN unless you are on a campus network (instructions for this are linked in the first step). Step 2 reads: ‘For this example, we’ll assume you have a Shiny application ready to deploy in a folder called myapp on your computer.’ Here, the folder is the myapp folder included in this assignment. For the 7th step ‘Upload the myapp folder you prepared in step 1 inside the

Plate 1: Problem with title: the text is cut off.

ShinyApps folder’ the text ‘...step 1 inside...’ should read ‘... step 2 inside...’. For step 5, you may use a free sftp client such as Cyberduck

(https://cyberduck.io/). If you use Cyberduck, make sure to specify “SFTP (SSH File Transfer Protocol)” in the drop down box for ‘Open Connection’. If you receive a message ‘Unknown fingerprint’ you may click ‘Allow’ if you can confirm that you are on the SFU VPN and that your computer is free of viruses or malware.

Provide some screenshot in a pdf of the Shiny App working, including the URL. Include a link in the pdf to the Shiny App (with your Compute ID in the URL). The Shiny App must remain live for at least two weeks after you hand in the assignment, so that we can mark it.

 b) The title of the density plot is cut off in the plot on the right as indicated by the red arrow in Plate 1 (i.e., the top of the text is missing). Also, the title does not change when the selected variable changes, and instead provides meaningless information. Change the code so that the title is not cut off, and so that the title gives the name of the variable being plotted. Provide code and screens

 

 c) Make a new Shiny App called myapp2 that shows density plots for the variables in the dataset that you selected for the last question of Assignment 01 (you will have to modify the code

to read in the dataset, and upload the dataset to the myapp2 directory of your SFU Shiny App server). Make the side bar drop down box indicate variables from that dataset. Have the same fix to the title of the density plots that you did in the above part. If there are more than 10 variables in the dataset that you selected in Assignment 01, have the side bar only list the first 5. Provide in a pdf screenshots, code (all of server.R and ui.R), and a URL to your App on SFU’s Shiny App server.

Question 2: Deploying a public website
a) This is a bonus question where you will deploy the App you made in Question 1. Part c) on the heroku cloud service. This service has free tiers (which you will use), and allows website applications to be scaled easily with commercial quality. For more information about heroku, read this about page: https://www.heroku.com/ what. Deploy myapp2 on heroku by following the steps below. Note that these steps are a year out of date and some of the steps may require modification. If you receive error messages, attempt to resolve them (the error message may point you in the direction of the solution, or you may search stackoverflow for the error and resolution) before contacting instructors. Provide a screenshot of the App working on heroku. Ensure that you are always using the free tier of the service. This question requires use of a local command line terminal. If you are starting to learn the terminal, please complete the terminal exercise provided on canvas.


1.  Create a heroku account on https://www.heroku.com/.

2.  Download and install the heroku command line interface: https:

//devcenter.heroku.com/articles/heroku-cli. Also: make sure you have the software git installed. You can check if you have git by typing git into a terminal. If you get an error, you can install git here: https://git-scm.com/downloads/.

3.   Log in to heroku through the command line interface: Open a terminal on your computer and enter the command heroku login.

4. You can create a heroku App through the heroku dashboard: https: //dashboard.heroku.com/, but in these steps we will create one manually from the command line. On the terminal, change to a project or Documents directory on your computer. This will be the parent directory of the local copy of your heroku App. Create a directory called lab07 with the command mkdir lab07. Change to that directory and create an empty git repository using the command git init. Create an empty heroku App with the command heroku apps:create STAT240-2022-MYAPP2-NAME. Here, make NAME a globally unique alphanumeric string (do not use your name or Compute ID, just use a random string or an alias).

5.  Enter the following command into the terminal. This will instruct heroku to use Shiny Apps: heroku buildpacks:set https://github.com/virtualstaticvoid/herokubuildpack-r.githeroku-16. This command must be all on one line.

6. Enter the command heroku stack:set heroku-16.

7.  Copy the R files from the directory heroku provided in this lab to the directory you are working in: run.R, server.R, ui.R.

8.    Commit the files to the git repository you have created using the following commands. First: git add *.R. Second: git commit -m ’Initial commit’.

9. Send your App to heroku with the command git push heroku master.

10.  Open a web browser and navigate to the URL https://STAT240-

2022-MYAPP2-NAME.herokuapp.com (here NAME is the token for your App that you chose in Step 4).

11.  Modify the App so that it works like the App you made in Question 1 Part c).

12.  Take screenshots of the App working.

13.  After you are done, turn off the App by entering the command heroku ps:scale web=0. You can also turn off the App by navigating to the URL https://dashboard.heroku.com and then logging in (if required) and then clicking on the App name in the list on the left and then clicking the Resources tab and then clicking the edit pencil to the right of the line beggining with web under the text Free Dynos and then clicking and dragging on the blue sliding circle to move it all the way to the left (off position) and then pressing the purple Confirm button.

14.  If you’d like to turn the App back on, use the command heroku ps:scale web=1. Always run heroku commands like this in the directory that the App is in (note that the name of the App is not specified, it’s inferred by your current directory).

15.  If you’d like to modify the App, modify the files and then update them on heroku using these three commands: 1) git add *.R. 2) git commit -m ’Update’. 3) git push heroku master.

More products