{"id":25059911,"url":"https://github.com/stla/shinychakraui","last_synced_at":"2025-04-14T14:24:48.957Z","repository":{"id":62459156,"uuid":"369297110","full_name":"stla/shinyChakraUI","owner":"stla","description":"A wrapper of the React library 'Chakra UI' for usage in Shiny.","archived":false,"fork":false,"pushed_at":"2022-01-05T14:02:25.000Z","size":15579,"stargazers_count":22,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-08T19:28:44.146Z","etag":null,"topics":["r","react","reactr","shiny"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/stla.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-20T18:05:08.000Z","updated_at":"2024-01-31T21:23:53.000Z","dependencies_parsed_at":"2022-11-02T00:45:24.938Z","dependency_job_id":null,"html_url":"https://github.com/stla/shinyChakraUI","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FshinyChakraUI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FshinyChakraUI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FshinyChakraUI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FshinyChakraUI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stla","download_url":"https://codeload.github.com/stla/shinyChakraUI/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248895581,"owners_count":21179260,"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":["r","react","reactr","shiny"],"created_at":"2025-02-06T15:55:46.401Z","updated_at":"2025-04-14T14:24:48.914Z","avatar_url":"https://github.com/stla.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\ntitle: \"shinyChakraUI\"\noutput: github_document\n---\n\n```{r setup, include=FALSE}\nknitr::opts_chunk$set(echo = TRUE, eval = FALSE)\n```\n\n```{r package}\nlibrary(shiny)\nlibrary(shinyChakraUI)\n```\n\nThe `shinyChakraUI` package is a wrapper of the React library `Chakra UI`. A \nvery good documentation of this library is available at \n\u003chttps://chakra-ui.com/\u003e.\n\n# Basics\n\n- Use `chakraPage` to define your Shiny UI.\n\n- Use `chakraComponent` to define a Chakra component.\n\nFor example, here is a Chakra alert component:\n\n![](https://raw.githubusercontent.com/stla/shinyChakraUI/main/inst/screenshots/chakraAlert.png)\n\n# React states\n\nYou can use React states with the help of the `withStates` function. Here is an \nexample:\n\n![](https://raw.githubusercontent.com/stla/shinyChakraUI/main/inst/screenshots/withStates.gif)\n\nThe states are defined in the second argument of the `withStates` function, in \na list. Here one state is defined: `heading = \"I am the heading.\"`. The state \nis obtained in the Chakra component with the help of the R function `getState`. \nTo change the value of a state, you have to resort to JavaScript. The JavaScript \ncode must be given as a character string in the R function `jseval`. Here it is \ngiven in the `onClick` attribute of the Chakra button: \n`jseval(\"() =\u003e setState('heading', 'New heading!')\")`. When the button is \nclicked, the `'heading'` state takes the new value `'New heading!'`.\n\n# Writing JSX code\n\nSo far, we built React components with the help of the `Tag` constructor. It is \nalso possible to build a React component by writing its JSX code, with the help \nof the `jsx` function. Here is an example:\n\n![](https://raw.githubusercontent.com/stla/shinyChakraUI/main/inst/screenshots/jsx.gif)\n\nThe `jsx` function takes two arguments. The first one is the JSX element and \nthe second one, named `preamble`, is some JavaScript code to be executed at first. \n\n# Setting a React state from Shiny server\n\nIn the `'heading'` React state example, we set the new value of the state with \nthe help of the JavaScript function `setState`, executed from the R function \n`jseval`. It is also possible to set a React state from the Shiny server function, \nwith the `setReactState` function. It offers more possibilities: it allows to \nset as a new value a React component, a JSX element, a Shiny widget, or some \nHTML code. Here is an example:\n\n![](https://raw.githubusercontent.com/stla/shinyChakraUI/main/inst/screenshots/setReactState.gif)\n\n# More examples\n\nRun `chakraExamples()` to get the list of available examples provided in the \npackage. See also the examples of the built-in widgets `chakraAlertDialog`, \n`chakraCheckboxWithChildren`, `chakraDrawer`, `chakraSlider`, \n`chakraCombinedSlider`, and `chakraModal`.\n\n# The 'JSX parser' RStudio addin\n\nThe package provides a RStudio addin which allows to convert some JSX code to \nthe corresponding R code to use in the `chakraComponent` function. For example, \nconsider this JSX code:\n\n```jsx\n\u003cCheckboxGroup colorScheme=\"green\" defaultValue={[\"naruto\", \"kakashi\"]}\u003e\n  \u003cHStack\u003e\n    \u003cCheckbox value=\"naruto\"\u003eNaruto\u003c/Checkbox\u003e\n    \u003cCheckbox value=\"sasuke\"\u003eSasuke\u003c/Checkbox\u003e\n    \u003cCheckbox value=\"kakashi\"\u003ekakashi\u003c/Checkbox\u003e\n  \u003c/HStack\u003e\n\u003c/CheckboxGroup\u003e\n```\n\nCopy it to your clipboard, and then select the 'JSX parser' addin in the \nRStudio Addins menu. You'll get this R code:\n\n```r\nTag$CheckboxGroup(\n  colorScheme = \"green\", defaultValue = list(\"naruto\", \"kakashi\"),\n  Tag$HStack(\n    Tag$Checkbox(value = \"naruto\", \"Naruto\"),\n    Tag$Checkbox(value = \"sasuke\", \"Sasuke\"),\n    Tag$Checkbox(value = \"kakashi\", \"kakashi\")\n  )\n)\n```\n\nThis JSX parser is not perfect. It may fail, or you may have to manually modify \nthe output.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstla%2Fshinychakraui","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstla%2Fshinychakraui","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstla%2Fshinychakraui/lists"}