mirror of
https://github.com/agdamsbo/prioritized.grouping.git
synced 2025-09-12 10:39:39 +02:00
2 lines
13 KiB
JSON
2 lines
13 KiB
JSON
|
[{"name":"server.R","content":"server <- function(input, output, session) {\n library(dplyr)\n library(tidyr)\n library(ROI)\n library(ROI.plugin.symphony)\n library(ompr)\n library(ompr.roi)\n library(magrittr)\n library(ggplot2)\n library(viridisLite)\n library(patchwork)\n library(openxlsx)\n # source(\"https://git.nikohuru.dk/au-phd/PhysicalActivityandStrokeOutcome/raw/branch/main/side%20projects/assignment.R\")\n source(here::here(\"R/group_assign.R\"))\n \n dat <- shiny::reactive({\n # input$file1 will be NULL initially. After the user selects\n # and uploads a file, head of that data file by default,\n # or all rows if selected, will be shown.\n \n req(input$file1)\n # Make laoding dependent of file name extension (file_ext())\n ext <- file_extension(input$file1$datapath)\n \n if (ext == \"csv\") {\n df <- read.csv(input$file1$datapath,na.strings = c(\"NA\", '\"\"',\"\"))\n } else if (ext %in% c(\"xls\", \"xlsx\")) {\n df <- openxlsx::read.xlsx(input$file1$datapath,na.strings = c(\"NA\", '\"\"',\"\"))\n \n } else {\n stop(\"Input file format has to be either '.csv', '.xls' or '.xlsx'\")\n }\n \n return(df)\n })\n \n dat_pre <- shiny::reactive({\n \n # req(input$file2)\n # Make laoding dependent of file name extension (file_ext())\n if (!is.null(input$file2$datapath)){\n ext <- file_extension(input$file2$datapath)\n \n if (ext == \"csv\") {\n df <- read.csv(input$file2$datapath,na.strings = c(\"NA\", '\"\"',\"\"))\n } else if (ext %in% c(\"xls\", \"xlsx\")) {\n df <- openxlsx::read.xlsx(input$file2$datapath,na.strings = c(\"NA\", '\"\"',\"\"))\n \n } else {\n stop(\"Input file format has to be either '.csv', '.xls' or '.xlsx'\")\n }\n \n return(df)\n } else {\n return(NULL)\n }\n\n })\n \n assign <-\n shiny::reactive({\n assigned <- group_assignment(\n ds = dat(),\n excess_space = input$ecxess,\n pre_assign = dat_pre()\n )\n return(assigned)\n })\n \n \n output$raw.data.tbl <- shiny::renderTable({\n assign()$export\n })\n \n output$pre.assign <- shiny::renderTable({\n dat_pre()\n })\n \n output$input <- shiny::renderTable({\n dat()\n })\n \n output$assign.plt <- shiny::renderPlot({\n assignment_plot(assign())\n })\n \n # Downloadable csv of selected dataset ----\n output$downloadData <- shiny::downloadHandler(\n filename = \"group_assignment.csv\",\n\n content = function(file) {\n write.csv(assign()$export, file, row.names = FALSE)\n }\n )\n \n}\n","type":"text"},{"name":"ui.R","content":"ui <- shiny::fluidPage(\n ## -----------------------------------------------------------------------------\n ## Application title\n ## -----------------------------------------------------------------------------\n \n shiny::titlePanel(\"Assign groups based on costs/priorities.\",\n windowTitle = \"Group assignment calculator\"),\n shiny::h5(\n \"Please note this calculator is only meant as a proof of concept for educational purposes,\n and the author will take no responsibility for the results of the calculator.\n Uploaded data is not kept, but please, do not upload any sensitive data.\"\n ),\n \n ## -----------------------------------------------------------------------------\n ## Side panel\n ## -----------------------------------------------------------------------------\n \n \n ## -----------------------------------------------------------------------------\n ## Single entry\n ## -----------------------------------------------------------------------------\n shiny::sidebarLayout(\n shiny::sidebarPanel(\n shiny::numericInput(\n inputId = \"ecxess\",\n label = \"Excess space\",\n value = 1,\n step = .05\n ),\n shiny::p(\"As default, the program will try to evenly distribute subjects in groups. \n This factor will add more capacity to each group, for an overall lesser cost, \n
|