# 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 <- fluidPage( # theme = bs_theme(bootswatch = "minty"), title = "Simulation of Study Success", # sidebar = sidebar(width = "20%", # , # hr() # ), column(6, h1("Input"), wellPanel( style = "background-color: transparent;", fluidRow( style = "display: flex;", prettySwitch("sex", "Male?", fill = TRUE, status = "primary"), 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"), prettySwitch("parents_spc_need", "Parent have special needs?", fill = TRUE, status = "primary") ), fluidRow( style = "display: flex;", selectInput("parents_occupation_category", "Parents Occupation Category", choices = c("Civil Servants", "Labor Workers", "Private Employee"), width = "33.333%"), numericInput("household_income", "Household Income", 4000000, min = 0, max = 19949598, width = "33.333%"), selectInput("parents_education_level_cat", "Parent Education Level", choices = c("Bachelor", "Diploma", "Master/Doctorate", "Senior Highschool", "Junior Highschool", "Elementary School", "Unschooled"), width = "33.333%") ), fluidRow( style = "display: flex;", selectInput("school_location", "School Location", choices = c("Rural", "Urban"), width = "50%"), numericInput("home_sch_dist", "School Distance (km)", value = 3, min = 0, width = "50%") ), fluidRow( selectInput("highsch_major", "Highschool Major", width = "60%", choices = c("Natural Science", "Social Sciences", "Language Studies")), ), fluidRow( style = "display: flex;", numericInput("math_score", "Math Score", 50, min = 0, max = 100, width = "20%"), numericInput("science_score", "Science Score", 50, min = 0, max = 100, width = "20%"), numericInput("english_score", "English Score", 50, min = 0, max = 100, width = "20%"), numericInput("indonesian_score", "Bahasa Indonesia Score", 50, min = 0, max = 100, width = "20%"), numericInput("social_score", "Social Score", 50, min = 0, max = 100, width = "20%") ), fluidRow(selectInput("university", "University", choices = c("Private", "Public"))) ), ), column(6, h1("Output"), wellPanel( echarts4rOutput("gpa_plot"), style = "background-color: transparent;" ) ) # tableOutput("tblout") ) 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_x_axis(name = "Predicted GPA Final", nameLocation = "center", nameGap = 30, min = 0, max = 4, interval = 0.5) |> e_y_axis(name = "Univ. Major Schema", nameLocation = "start", inverse = TRUE) |> e_grid(left = "20%", right = "5%") |> e_legend(show = FALSE) } ) } shinyApp(ui, server)