{"repo_name": "colors", "file_name": "/colors/app.R", "inference_info": {"prefix_code": "library(shiny)\nlibrary(purrr)\nlibrary(scales)\nlibrary(ggplot2)\nlibrary(stringr)\nlibrary(magrittr)\nlibrary(reactable)\nlibrary(gridExtra)\nlibrary(htmltools)\nlibrary(data.table)\nlibrary(shinyWidgets)\nlibrary(colourpicker)\nlibrary(shinydashboard)\n\nui <- dashboardPage(\n dashboardHeader(title = \"科研绘图配色推荐器\",titleWidth = \"100%\"),\n dashboardSidebar(disable = TRUE, collapsed = TRUE),\n dashboardBody(\n uiOutput(\"uipanel\"),\n tags$hr(),\n tags$div(align = \"center\", \n tags$p(\"\\ua9 2021-2024, Lcpmgh, All rights reserved.\", style=\"height:8px\"),\n tags$div(align = \"center\",\n actionLink(inputId = \"\", label = \"lcpmgh \", icon = icon(\"github\"), onclick =\"window.open('https://github.com/lcpmgh')\"),\n tags$p(\" \", style = \"display:inline;white-space:pre\"),\n actionLink(inputId = \"\", label = \"lcpmgh@gmail.com\", icon = icon(\"envelope\"), onclick =\"window.location.href='mailto:lcpmgh@gmail.com'\"),\n tags$p(\" \", style = \"display:inline;white-space:pre\"),\n actionLink(inputId = \"\", label = \"lcpmgh.com\", icon = icon(\"home\"), onclick =\"window.location.href='http://lcpmgh.com/'\")\n ),\n tags$div(align = \"center\",\n tags$a(\"冀ICP备2022003075号\", target=\"_blank\", href=\"https://beian.miit.gov.cn\", style=\"color:#06c; display:inline;\"),\n tags$p(\" \", style = \"display:inline;white-space:pre\"),\n # tags$img(src=\"gaba.png\"),\n tags$a(\"川公网安备51010702002736\", target=\"_blank\", href=\"http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=51010702002736\", style=\"color:#06c; display:inline;\")\n )\n )\n )\n)\n\nserver <- function(input, output, session){\n # 数据\n colors <- readLines(\"@colors.txt\") %>% str_split(\",\") %>% lapply(., sort) %>% .[!duplicated(.)] #读取、排序、去重\n colors_nasc <- map_int(colors, length) %>% order() %>% colors[.] #按子颜色数量排序\n colors_table <- data.frame(col_id=1:length(colors_nasc), col_num=map_int(colors_nasc, length)) #颜色序号数量表\n setDT(colors_table)\n colors_sect <- colors_table[, c(min(.SD),max(.SD)), .SDcols=1,by=\"col_num\"] %>% \n .[, type:=rep(c(\"min\", \"max\"), nrow(.)/2)] %>% \n dcast(., col_num~type, value.var = \"V1\") %>% \n rbind(data.table(col_num=\"all\", \n max=max(colors_table$col_id), \n min=min(colors_table$col_id)), .) #提取每个数量区间的id范围 \n # 函数\n examp_plot <- function(id, colors_nasc=NULL, custom=c(\"#F5A889\", \"#ACD6EC\"), alp=0.1){\n # 函数,根据给定颜色id或自定义的颜色,画4个案例图\n # id=0时自定义颜色,否则按colors_nasc中的颜色\n if(id == 0){\n tcolor <- custom\n ncolor <- length(tcolor)\n } else{\n tcolor <- colors_nasc[[id]]\n ncolor <- length(tcolor)\n }\n # 图1.bar\n dat_bar <- data.frame(a=sample(letters, ncolor, replace = F), \n b=runif(ncolor, 7, 10))\n p_bar <- ggplot(dat_bar, aes(a, b, fill=a))+\n geom_bar(color=\"black\", stat = \"identity\", alpha=alp)+\n scale_y_continuous(expand = c(0,0,0,0.1))+\n scale_fill_manual(values = tcolor)+\n labs(x=\"x-axis\", y=\"y-axis\", title = \"Bar Chart with outlines\")+\n theme_bw()+theme(plot.title = element_text(hjust = 0.5))\n # 图2.box\n dat_box <- data.frame(a=sample(letters, ncolor, replace = F),\n b=runif(ncolor*20, 7, 10))\n p_box <- ggplot(dat_box, aes(a, b, fill=a))+\n stat_boxplot(geom = \"errorbar\", linewidth=0.8, width = 0.3)+\n geom_boxplot(alpha=alp)+\n scale_fill_manual(values = tcolor)+\n labs(x=\"x-axis\", y=\"y-axis\", title = \"Boxplot with outlines\")+\n theme_bw()+theme(plot.title = element_text(hjust = 0.5))\n # 图3.point\n dat_point <- data.frame(a=rep(runif(30), ncolor),\n b=rep(runif(30), ncolor),\n t=rep(sample(letters, ncolor, replace = F), 30))\n p_point <- ggplot(dat_point, aes(a, b, color=t, fill=t))+\n geom_point(shape=21, size=5, alpha=alp)+\n scale_color_manual(values = tcolor)+\n scale_fill_manual(values = tcolor)+\n labs(x=\"x-axis\", y=\"y-axis\", title = \"scatterplot without outlines\")+\n theme_bw()+theme(plot.title = element_text(hjust = 0.5))\n # 图4.line\n dat_line <- data.frame(a=rep(1:20, ncolor),\n b=rep(1:ncolor, each=20)+rnorm(20*ncolor, 0, 0.3), \n t=rep(sample(letters, ncolor), each=20))\n p_line <- ggplot(dat_line, aes(a, b, color=t, group=t))+\n geom_line(linewidth=1, alpha=alp)+\n scale_color_manual(values = tcolor)+\n labs(x=\"x-axis\", y=\"y-axis\", title = \"Line chart without outlines\")+\n theme_bw()+theme(plot.title = element_text(hjust = 0.5))\n # 合并\n p <- grid.arrange(p_bar, p_box, p_point, p_line, padding=0, nrow = 2, ncol = 2)\n return(p)\n } \n iscolors <- ", "suffix_code": "\n \n ##### ui #####\n output$uipanel <- renderUI({\n tagList(\n tags$head(tags$link(rel = \"shortcut icon\", href = \"pmgh.ico\")),\n tags$style(HTML(\".custom-margin {margin-bottom: 20px;}\")),\n tags$div(class = \"custom-margin\",\n HTML(\"