R Shiny App of Pokemon Data Set
January 27, 2020 By Pascal Schmidt Personal Project R
Recently, I looked through my university folder and found a project that I have created in my STAT 240 class. Then I thought about this picture here. Therefore, I decided to publish my first ever Shiny app where I analyzed a Pokemon data set.
If you want a better layout, then visit the visualizations on the Shiny server.
Code:
###############
### SERVER: ###
###############
library(shiny)
library(ggplot2)
library(dplyr)
library(stringr)
library(RColorBrewer)
library(wordcloud)
shinyServer(function(input, output) {
output$plot <- renderPlot({
van <- read.csv("van.csv")
data <- subset(van,
gender %in% input$gender)
data.1 <- subset(data,
weather %in% input$weather)
p <- ggplot(data.1, aes(level, cp)) +
geom_point(shape = input$size) +
ggtitle(input$title)
if (input$fit) {
p <- p + geom_smooth(method = "lm", se = F)
}
if(input$AddCI){
p <- p + geom_smooth(method = "lm", se = T)
}
print(p)
})
#########END OF TAB 1
#########START OF TAB 2
output$DatePlot <- renderPlot({
all <- read.csv("all.csv")
data.2 <- subset(all,
time %in% input$time)
q <- ggplot(data.2, aes(x = time.of.Day)) +
geom_histogram(binwidth = input$decimal) +
ggtitle("Time of the Day Players are hunting for Pokemon") + xlab("Time of the Day") +
scale_x_continuous(breaks = seq(0, 12, 1)) + geom_density()
q
})
#########END OF TAB 2
#########START OF TAB 3
output$WordcloudPlot <- renderPlot({
all.cities <- read.csv("all.cities.csv")
data.3 <- subset(all.cities,
city %in% input$city)
wordcloud(words = data.3$Words, freq = data.3$Freq, min.freq = input$freq, max.words=input$max, colors = rainbow(8), random.order = FALSE)
})
#########END OF TAB 3
})
###########
### UI: ###
###########
library(shiny)
library(shiny)
library(ggplot2)
library(dplyr)
library(stringr)
library(RColorBrewer)
library(wordcloud)
van <- read.csv("van.csv")
all <- read.csv("all.csv")
all.cities <- read.csv("all.cities.csv")
shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
# Add a title text input
textInput("title", "Title", "Level vs Cp"),
# numeric input
numericInput("size", "Shape", 16, 1, 25),
# Add a checkbox for line of best fit
checkboxInput("fit", strong("Add Least Squares Line"), FALSE),
# Add radio buttons
radioButtons("gender", "Gender",
choices = c("Male", "Female")),
# dropdown selector
selectInput("weather", "Weather",
choices = levels(van$weather),
multiple = FALSE,
selected = "None"),
conditionalPanel(
condition = "input.fit == true", #Note th lowercase logical
helpText(HTML("<h3>You might want to include the Confidence Bands for the Least Squares Line</h3>")), #This is just big text
checkboxInput("AddCI", strong("Add Confidence Bands for Least Squares Line"), FALSE)),
radioButtons("time", "Time of the Day for Histogram",
choices = levels(all$time)),
sliderInput("decimal", "Changing Binwidth of Histogram",
min = 0, max = 0.05,
value = 0.025, step = 0.0005),
# Add radio buttons for Wordcloud
radioButtons("city", "Choose the City of your Wordcloud",
choices = levels(all.cities$city)),
sliderInput("freq",
"Minimum Frequency:",
min = 40, max = 11000, value = 500),
sliderInput("max",
"Maximum Number of Words:",
min = 50, max = 250, value = 80)
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Pokemon Data", plotOutput("plot")),
tabPanel("Time Of the Day Insights", plotOutput("DatePlot")),
tabPanel("Twitter Wordclouds", plotOutput("WordcloudPlot")),
tabPanel("About",source("about.R")$value()))
)
)
))
Recent Posts
Recent Comments
- Kardiana on The Lasso – R Tutorial (Part 3)
- Pascal Schmidt on RSelenium Tutorial: A Tutorial to Basic Web Scraping With RSelenium
- Pascal Schmidt on Dynamic Tabs, insertTab, and removeTab For More efficient R Shiny Applications
- Gisa on Persistent Data Storage With a MySQL Database in R Shiny – An Example App
- Nicholas on Dynamic Tabs, insertTab, and removeTab For More efficient R Shiny Applications