3  ShinyApp Assignment

Author

Canseza Avağ Erdurak

Published

Nov 27, 2022

Data Wrangling

First of all, I installed packages.

library(dplyr)
library(readxl)
library(tidyr)
library(ggplot2)
library(reshape)
library(tidyverse)
library(scales)
library(openxlsx)

options(dplyr.summarise.inform = FALSE)

I fetched raw data and stored in students variable.

students<-read_excel("foreign_students_by_nationality_2021_2022.xlsx")

I high-level look at raw data which has 7 columns and 10.461 rows.

students %>% glimpse()
Rows: 10,461
Columns: 7
$ `Üniversite Adı`  <chr> "ABDULLAH GÜL ÜNİVERSİTESİ", "ABDULLAH GÜL ÜNİVERSİT…
$ `Üniversite Türü` <chr> "DEVLET", "DEVLET", "DEVLET", "DEVLET", "DEVLET", "D…
$ `İl Adı`          <chr> "KAYSERİ", "KAYSERİ", "KAYSERİ", "KAYSERİ", "KAYSERİ…
$ Uyruk             <chr> "AFGANİSTAN İSLAM CUMHURİYETİ", "ALMANYA FEDERAL CUM…
$ E                 <chr> "1", "1", "0", "8", "4", "1", "1", "1", "1", "1", "1…
$ K                 <chr> "0", "0", "1", "2", "3", "0", "0", "1", "2", "0", "0…
$ T                 <chr> "1", "1", "1", "10", "7", "1", "1", "2", "3", "1", "…

I changed column names so that I could omit white spaces and Turkish characters.

new_cols <- c("university","university_type","country","nationality","male","female","total")

colnames(students) <- new_cols

I removed any incomplete cases.

students <- na.omit(students) 

I selected columns from university to female.

students <- students %>%
  select('university':'female')

I unpivoted male and female column as gender column by using melt function.

students <- reshape2::melt(students, id = c("university", "university_type", "country", "nationality"), variable.name = "gender", value.name="count")

I converted count column as numeric.

students$count <- as.numeric(students$count)

I saved file as RDS.

saveRDS(data, file = "apps/foreign_students_app/students.Rds")

I created another excel file named foreign_students.xlsx derived from raw data. I used this file in shiny app.

write.xlsx(students, "ForeignStudentAnalysis/foreign_students.xlsx")

Shinyapps.io

https://avagcanseza.shinyapps.io/foreign_students_app/

Command for local running

shiny::runGitHub(repo = "pjournal/mef06-avagcanseza",subdir="apps/foreign_students_app")