{"id":13733668,"url":"https://github.com/daattali/shiny-colour-gradient-input","last_synced_at":"2025-04-11T00:44:53.140Z","repository":{"id":151156193,"uuid":"214586139","full_name":"daattali/shiny-colour-gradient-input","owner":"daattali","description":"Colour gradient input for R-Shiny","archived":false,"fork":false,"pushed_at":"2019-11-20T21:30:05.000Z","size":24,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T00:44:38.832Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daattali.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"daattali"}},"created_at":"2019-10-12T05:48:22.000Z","updated_at":"2024-01-17T09:54:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"b6a27aa9-4e87-462e-a60a-c0a56b24efc1","html_url":"https://github.com/daattali/shiny-colour-gradient-input","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daattali%2Fshiny-colour-gradient-input","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daattali%2Fshiny-colour-gradient-input/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daattali%2Fshiny-colour-gradient-input/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daattali%2Fshiny-colour-gradient-input/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daattali","download_url":"https://codeload.github.com/daattali/shiny-colour-gradient-input/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248322604,"owners_count":21084336,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T03:00:47.182Z","updated_at":"2025-04-11T00:44:53.121Z","avatar_url":"https://github.com/daattali.png","language":"R","funding_links":["https://github.com/sponsors/daattali"],"categories":["UI Components","R"],"sub_categories":["Color Picker"],"readme":"# Colour gradient input for R-Shiny\n\nA colour gradient picker for Shiny, implemented as a shiny module. This can be used, for example, in ggplots with the `scale_color_gradientn()` function. This can most likely be improved upon by making it a proper input instead of a module--left as an exercise for the reader :)\n\n![screenshot](https://i.imgur.com/KfA7htH.png)\n\nThe UI function is `gradientInputUI()` and has two parameters:\n\n- **width**: The width of the input (either in pixels or in percent) (default: 300px)\n- **resource_path**: The path where the JavaScript and CSS files are located.\n\nThe server function is `gradientInput()` and has 4 parameters:\n\n- **init_cols**: The initial state of the colour gradient. There are 4 different values that are accepted:\n    1. If a single integer N is provided (eg. `5`), then the input is initialized with N colours. The colours are random and their positions are evenly distributed. If nothing is provided, the default behaviour is to initialize the input with 2 colours.\n    2. If a vector of N integers is provided (each number must be between 0 and 100) (eg. `c(10, 40, 90)`), the input is initialized with N different colours and each number in the vector corresponds to the position of one colour. The colours are random.\n    3. If a vector of N colours is provided (a colour can be any R colour name or a HEX string) (eg. `c(\"red\", \"blue\", \"#00FF00\")`), the input is initialized with these N colours. The positions of the colours are distributed evenly.\n    4. If a dataframe with 2 columns \"col\" (any R colour) and \"position\" (number between 0 and 100) and N rows is provided, the input is initialized with N colours. Each colour uses the \"col\" column as its initial colour and \"position\" as its initial position.\n- **allow_modify**: Whether or not the user can add, delete, and change positions of colours. (default: true)\n- **col_expand**: Whether or not the colour input can expand into a full colour picker text box that lets the user write colour names in English. (default: false)\n\nThe return value is a list with two items:\n- `result`: a dataframe with 2 columns: `position` (the left position, between 0 and 100) and `col` (the colour hex string).\n- `reset`: a function that will reset the gradient input back to its original state.\n\n\nExample usage:\n\n```\nlibrary(shiny)\nsource(\"gradientInput.R\")\n\nui \u003c- fluidPage(\n  gradientInputUI(\"cols\"),\n  tableOutput(\"result\"),\n  actionButton(\"reset\", \"Reset\")\n)\nserver \u003c- function(input, output, session) {\n  gradient \u003c- callModule(gradientInput, \"cols\", init_cols = c(10, 50, 70))\n  output$result \u003c- renderTable(gradient$result())\n  \n  observeEvent(input$reset, {\n    gradient$reset()\n  })\n}\nshinyApp(ui, server)\n```\n\nRequired packages: `glue`, `colourpicker`, `shinyjs`, `shinyjqui`, `uuid`, `dplyr`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaattali%2Fshiny-colour-gradient-input","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaattali%2Fshiny-colour-gradient-input","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaattali%2Fshiny-colour-gradient-input/lists"}