{"id":13736336,"url":"https://github.com/devOpifex/communicate","last_synced_at":"2025-05-08T12:32:41.537Z","repository":{"id":204288064,"uuid":"711008505","full_name":"devOpifex/communicate","owner":"devOpifex","description":"💬 Communicate between client and server in Shiny via HTTP","archived":false,"fork":false,"pushed_at":"2024-05-29T12:11:05.000Z","size":355,"stargazers_count":23,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-15T04:32:11.821Z","etag":null,"topics":["client-server","http","javascript","rstats"],"latest_commit_sha":null,"homepage":"https://communicate.opifex.org","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devOpifex.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2023-10-28T00:29:22.000Z","updated_at":"2024-11-09T04:59:30.000Z","dependencies_parsed_at":"2024-11-15T12:16:32.149Z","dependency_job_id":null,"html_url":"https://github.com/devOpifex/communicate","commit_stats":null,"previous_names":["devopifex/communicate"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devOpifex%2Fcommunicate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devOpifex%2Fcommunicate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devOpifex%2Fcommunicate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devOpifex%2Fcommunicate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devOpifex","download_url":"https://codeload.github.com/devOpifex/communicate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253068971,"owners_count":21848896,"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":["client-server","http","javascript","rstats"],"created_at":"2024-08-03T03:01:19.996Z","updated_at":"2025-05-08T12:32:36.507Z","avatar_url":"https://github.com/devOpifex.png","language":"R","readme":"\u003cdiv align=\"center\"\u003e\n\n\u003cimg src=\"inst/logo.png\" height=200 /\u003e\n\nSmall framework to communicate between Shiny client and server via HTTP requests.\nRun `communicate::example()` for a short demo.\n\n[Site](https://communicate.opifex.org/)\n\n\u003c/div\u003e\n\n## Installation\n\n```r\n# install.packages(\"remotes\")\nremotes::install_github(\"devOpifex/communicate\")\n```\n\n## How it works\n\nCreate a shiny application and \"commincation channels.\"\nAdd callback functions with `com`.\n\n```r\nlibrary(shiny)\nlibrary(communicate)\n\nadd \u003c- \\(x){\n  x + 2\n}\n\nui \u003c- fluidPage(\n  h1(\"Hello\")\n)\n\nserver \u003c- \\(input, output, session){\n  com(\"add\", add)\n}\n\nshinyApp(ui, server)\n```\n\nThen use the JavaScript library to communicate.\n\n```r\nlibrary(shiny)\nlibrary(communicate)\n\nadd \u003c- \\(x){\n  x + 2\n}\n\nscript \u003c- \"\n  $('#btn').on('click', () =\u003e {\n    communicate.com('add', {x: 1})\n      .then(res =\u003e alert(`equals: ${res}`));\n  })\n\"\n\nui \u003c- fluidPage(\n  # import dependencies\n  useCommunicate(),\n  h1(\"Hello\"),\n  tags$a(\"Communicate\", id = \"btn\"),\n  tags$script(HTML(script))\n)\n\nserver \u003c- \\(input, output, session){\n  com(\"add\", add)\n}\n\nshinyApp(ui, server)\n```\n\n### Types\n\nThough optional it is recommended to specify the types of the arguments\nof your callback function. This enables type conversion and type check when communicating from the \nclient.\n\nExisting types:\n\n- `Character`\n- `Numeric`\n- `Integer`\n- `Date`\n- `Dataframe`\n- `Posixct`\n- `Posixlt`\n- `Character`\n- `List`\n- `Function`\n\n```r\nlibrary(shiny)\nlibrary(communicate)\n\nadd \u003c- \\(x){\n  x + 2\n}\n\nscript \u003c- \"\n  $('#btn').on('click', () =\u003e {\n    communicate.com('add', {x: 1})\n      .then(res =\u003e alert(`equals: ${res}`));\n  })\n\"\n\nui \u003c- fluidPage(\n  # import dependencies\n  useCommunicate(),\n  h1(\"Hello\"),\n  tags$a(\"Communicate\", id = \"btn\"),\n  tags$script(HTML(script))\n)\n\nserver \u003c- \\(input, output, session){\n  com(\"add\", add)(x = Integer)\n}\n\nshinyApp(ui, server)\n```\n\n### Defaults\n\nYou can also specifiy callback functions' argument defaults as done below.\n\n```r\nlibrary(shiny)\nlibrary(communicate)\n\nadd \u003c- \\(x, y){\n  x + y\n}\n\nscript \u003c- \"\n  $('#btn').on('click', () =\u003e {\n    communicate.com('add', {x: 1})\n      .then(res =\u003e alert(`equals: ${res}`));\n  })\n\"\n\nui \u003c- fluidPage(\n  # import dependencies\n  useCommunicate(),\n  h1(\"Hello\"),\n  tags$a(\"Communicate\", id = \"btn\"),\n  tags$script(HTML(script))\n)\n\nserver \u003c- \\(input, output, session){\n  com(\"add\", add)(x = Integer, y = Numeric)(y = 1.1)\n}\n\nshinyApp(ui, server)\n```\n\n## JavaScript\n\nAccessible from `communicate`, functions:\n\n- `com` - communicate.\n- `hasCom` - check if communication channel registered.\n- `getCom` - get communication channel and its arguments.\n- `getComs` - get all communication channels registered.\n\n## Dependency\n\nYou import the dependency with `useCommunicate()`.\nAlternatively you can install the npm package, \ne.g.: if you use [packer](https://packer.john-coene.com/).\n\n```bash\nnpm install @devopifex/communicate\n```\n\nOr with packer:\n\n```r\npacker::npm_install(\"@devopifex/communicate\")\n```\n\n### Usage\n\n```js\ncommunicate.hasCom(\"add\")\n\ncommunicate.getCom(\"add\")\n\ncommunicate.com(\"add\", {x: 1, y: 2})\n  .then(data =\u003e console.log(data))\n  .catch(error =\u003e console.error(error))\n```\n\n","funding_links":[],"categories":["R","Backend"],"sub_categories":["API Frameworks"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FdevOpifex%2Fcommunicate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FdevOpifex%2Fcommunicate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FdevOpifex%2Fcommunicate/lists"}