

The Shiny website has also a big gallery of apps you can explore. I’ve even started to set up my own Shiny Server using DigitalOcean (see my recent post on that: Run shiny server on your own DigitalOcean droplet): Shiny apps can be very helpful to make statistical concepts and theories more accessible and I started to use it more and more in my stats courses at the university. Since you need to run R in the background you can either launch a Shiny app directly in your R Studio IDE or host it on a website that is connected to a Shiny server (e.g. R Studio hosts the cloud service where you can deploy your app). You can easily extend your Shiny apps with CSS themes, htmlwidgets, and JavaScript actions. The output of theses computations can be then shown as output in the UI. You just need to write an R script that follows a specific Shiny syntax and once you run the script, the package builds a HTML file as user interface (UI) with interactive input elements (based on Javascript) that trigger certain computations in R. īut in a nutshell, Shiny is an R package that builds interactive web apps straight from R. transparency of points), but at some point the UI might become too overwhelming for the user.If you are an R user but don’t know yet what Shiny and Shiny apps are, you definitely should read up on it on. There could also be more controls to let the user change certain aspects of the plot (e.g. For one, it would be nice if the user could upload their dataset through the app (instead of downloading my source code and assigning their dataset to the raw_df variable). There are certainly several improvements that can be made to this app. (Color does not work for heatmaps.)Ĭolor can be used for the one-dimensional plots as well: Below is an example of a colored scatterplot:Īs the screenshot below shows, color works for boxplots too. For simplicity, the app only allows plots to be colored by non-numeric variables. If the “X” variable is non-numeric, the app plots a bar plot showing counts:įinally, let’s talk about color. If the “X” variable is numeric, the app plots a histogram: If the user wants a visualization for just one variable, the user can set the “Y” variable to “None”. The plots above depict the joint distribution of two variables in the dataset. If two non-numeric variables are given, the app makes a heatmap depicting how often each combination is present in the data: If two numeric variables are given, it makes a scatterplot:įor scatterplots, the user has the option to jitter the points and/or to add a smoothing line:

In the screenshot above, one numeric variable and one non-numeric variable is given, so the app makes a boxplot. The type of plot the app makes depends on the type of variables given to it. The user can also control the number of observations using the slider, and choose the observations randomly or take the top from the dataset. The user can input the random seed for reproducibility. By default, it picks 1000 random observations or all the observations if the dataset has less than 1000 rows. First let me describe how the app selects the dataset it makes the plot for. The most interesting tab is probably the “Plot” tab. (These 15 rows are the first 15 rows of the dataset used to create the plot on the “Plot” tab.) The “Data Snippet” panel prints up to 15 rows of the dataset for a peek into what the dataset looks like. The last two tabs simply give the output of calling the summary and str functions on the entire dataset they are not affected by the controls in the side panel. There are a few versions of this app out there and I can’t find the exact source I used, but it was very close to the source code of this version.)Īs you can see from the screenshot below, the main panel (on the right) has 4 tabs. ( Credits: I worked off the source code for the “Diamonds Explorer” app.
#Movie explorer shinny code in r how to
In the rest of this post, I outline how to use this app.
#Movie explorer shinny code in r download
To use the app for your own dataset, download the raw R code here (just the app.R file) and assign your dataset to raw_df. You can use the app here to play around with the diamonds dataset from the ggplot2 package. To practice using Shiny, I created a simple app that you can use to perform simple exploratory data analysis. I recently learnt how to build basic R Shiny apps.
