moe / app.R
aephidayatuloh
change to shinywidgets
6f9b128
raw
history blame
4.1 kB
# library(readr)
library(tidyr)
library(parsnip)
library(workflows)
library(xgboost)
library(shiny)
library(shinyWidgets)
library(bslib)
library(dplyr)
library(echarts4r)
# df <- readr::read_csv("data/dummy_data.csv")
# b <- board_folder(path = ".")
# v <- b |>
# vetiver_pin_read(name = "MoE")
model <- readRDS("MoE-model.rds")
ui <- page_sidebar(
theme = bs_theme(bootswatch = "minty"),
title = "Pathway of Success",
sidebar = sidebar(width = "20%",
h5("Input"),
fluidRow(prettySwitch("playgroup", "Playgroup", fill = TRUE, status = "primary"),
prettySwitch("preelementary_school", "Pre-Elementary School", fill = TRUE, status = "primary"),
prettySwitch("gov_scholarship_holder", "Gov. Scholarship Holder", fill = TRUE, status = "primary"),
numericInput("home_sch_dist", "Home to School Distance", value = 3, min = 0),
prettySwitch("sex", "Male?", fill = TRUE, status = "primary"),
selectInput("school_location", "School Location", choices = c("Rural", "Urban")),
prettySwitch("parents_spc_need", "Parent have special needs?", fill = TRUE, status = "primary"),
selectInput("parents_occupation_category", "Parents Occupation Category",
choices = c("Civil Servants", "Labor Workers", "Private Employee")),
numericInput("household_income", "Household Income", 4000000, min = 0, max = 19949598),
selectInput("parents_education_level_cat", "Parent Education Level",
choices = c("Bachelor", "Diploma", "Master/Doctorate", "Senior Highschool", "Junior Highschool", "Elementary School", "Unschooled"))
),
fluidRow(
selectInput("highsch_major", "Highschool Major", width = "60%",
choices = c("Natural Science", "Social Sciences", "Language Studies")),
numericInput("math_score", "Math Score", 50, min = 0, max = 100, width = "39%")
),
fluidRow(
numericInput("science_score", "Science Score", 50, min = 0, max = 100, width = "48%"),
numericInput("english_score", "English Score", 50, min = 0, max = 100, width = "48%")
),
fluidRow(
numericInput("indonesian_score", "B. Indonesia Score", 50, min = 0, max = 100, width = "48%"),
numericInput("social_score", "Social Score", 50, min = 0, max = 100, width = "48%")
),
selectInput("university", "University", choices = c("Private", "Public")),
hr()
),
# tableOutput("tblout")
echarts4rOutput("gpa_plot")
)
server <- function(input, output, session) {
output$gpa_plot <- renderEcharts4r(
{
x <- data.frame(
playgroup = ifelse(input$playgroup, "Yes", "No"),
preelementary_school = ifelse(input$preelementary_school, "Yes", "No"),
gov_scholarship_holder = ifelse(input$gov_scholarship_holder, "Yes", "No"),
home_sch_dist = input$home_sch_dist,
sex = ifelse(input$sex, "Male", "Female"),
school_location = input$school_location,
parents_spc_need = ifelse(input$parents_spc_need, "Yes", "No"),
highsch_major = input$highsch_major,
parents_occupation_category = input$parents_occupation_category,
household_income = input$household_income,
parents_educatioin_level_category = input$parents_education_level_cat,
math_score = input$math_score,
science_score = input$science_score,
english_score = input$english_score,
indonesian_score = input$indonesian_score,
social_score = input$social_score,
university = input$university
)
x <- x |>
tidyr::expand_grid(univ_major = c("International Relations", "IT Department", "Law Department", "Psychology Department", "Statistic and Data Science"))
augment(x = model, new_data = x) |>
arrange(desc(.pred)) |>
slice_head(n = 5) |>
mutate(predict_GPA = round(.pred, 2)) |>
e_charts(univ_major) |>
e_bar(predict_GPA, label = list(show = TRUE)) |>
e_flip_coords() |>
e_y_axis(inverse = TRUE)
}
)
}
shinyApp(ui, server)