{"id":13707377,"url":"https://github.com/devOpifex/litter","last_synced_at":"2025-05-06T03:31:26.959Z","repository":{"id":134705209,"uuid":"427776595","full_name":"devOpifex/litter","owner":"devOpifex","description":":no_entry_sign: Lit components for shiny","archived":false,"fork":false,"pushed_at":"2024-04-13T21:08:53.000Z","size":2657,"stargazers_count":29,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-03T22:19:54.370Z","etag":null,"topics":["r","shiny"],"latest_commit_sha":null,"homepage":"https://litter.opifex.org","language":"HTML","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":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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-11-13T21:30:16.000Z","updated_at":"2024-08-03T14:51:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"81a8c429-fe86-4f2a-a00e-fb8806625b62","html_url":"https://github.com/devOpifex/litter","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/devOpifex%2Flitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devOpifex%2Flitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devOpifex%2Flitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devOpifex%2Flitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devOpifex","download_url":"https://codeload.github.com/devOpifex/litter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224484506,"owners_count":17318987,"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","shiny"],"created_at":"2024-08-02T22:01:29.438Z","updated_at":"2024-11-13T16:30:20.949Z","avatar_url":"https://github.com/devOpifex.png","language":"HTML","funding_links":[],"categories":["UI Components","HTML"],"sub_categories":["Bootstrap"],"readme":"\u003cdiv align=\"center\"\u003e\n\u003c!-- badges: start --\u003e\n\u003c!-- badges: end --\u003e\n\n\u003cimg src=\"inst/logo.png\" width=250 /\u003e\n\n[Lit](https://lit.dev) components for shiny, with a twist.\n\n\u003c/div\u003e\n\n## Inputs\n\nCurrently implemented inputs:\n\n- `litActionButton`\n- `litActionLink`\n- `litCheckboxesInput`\n- `litColorInput`\n- `litDatalistInput`\n- `litFilterInput`\n- `litPasswordInput`\n- `litTextInput`\n- `litTextAreaInput`\n- `litRadioInput`\n- `litSwitchInput`\n- `litTextLabelInput`\n- `litTogglerInput`\n- `litRangeInput`\n- `litSelectInput`\n- `litSelectizeInput`\n\n## Limitations\n\n- Only works with bslib's Bootstrap 5.\n- These inputs are not captured by Shiny's bookmarking session\n- These inputs are not captured by [shinytest2](https://rstudio.github.io/shinytest2/)\n\nThese limitations are unlikely to be lifted in the future.\n\n## Installation\n\nYou can install the development version of litter from [GitHub](https://github.com/) with:\n\n``` r\n# install.packages(\"remotes\")\nremotes::install_github(\"devOpifex/litter\")\n```\n\n## Example\n\n{litter} allows using multiple inputs with a single observer.\n\n```r\nlibrary(shiny)\nlibrary(litter)\n\nui \u003c- fluidPage(\n  theme = bslib::bs_theme(5L),\n  litActionButton(\n    name = \"btn\",\n    \"Button #1\"\n  ),\n  litActionButton(\n    name = \"btn\",\n    \"Button #2\"\n  )\n)\n\nserver \u003c- function(input, output, session){\n  observeEvent(input$btn, {\n    print(input$btn)\n  })\n}\n\nshinyApp(ui, server)\n```\n\n## Conventions\n\n- All input functions start in `lit`.\n- All inputs have a `value` (even if it can be a vector of multiple values)\n- All inputs can be updated with `update_input`\n- All inputs accept a `callback` argument (Javascript function)\n- Labels are not part of the input\n- All inputs accept a `send_on_render` argument\n- All inputs return data in the same format:\n\n```r\nlist(\n  props = list(),\n  id = \"\", # omitted if not set\n  value = 1L\n)\n```\n\n## Properties\n\nWhilst inputs that share `name` trigger the same input it can be difficult to \ndistinguish between inputs.\n\nFor this you can pass any \"prop\" to the three dot construct `...`.\nFor example, the application below will return the values set to `myProp`\nto `input$btn`.\n\n```r\nlibrary(shiny)\nlibrary(litter)\n\nui \u003c- fluidPage(\n  theme = bslib::bs_theme(5L),\n  litActionButton(\n    name = \"btn\",\n    \"Button #1\",\n    myProp = \"A\"\n  ),\n  litActionButton(\n    name = \"btn\",\n    \"Button #2\",\n    myProp = \"B\"\n  )\n)\n\nserver \u003c- function(input, output, session){\n  observeEvent(input$btn, {\n    print(input$btn)\n  })\n}\n\nshinyApp(ui, server)\n```\n\n## Callback\n\nYou can pass a JavaScript callback function,\nin which case it is called instead of sending the value\nto the shiny server.\n\n```r\nlibrary(shiny)\nlibrary(litter)\n\nui \u003c- fluidPage(\n  theme = bslib::bs_theme(5L),\n  litActionButton(\n    callback = \"() =\u003e {alert('Hello!')}\"\n  )\n)\n\nserver \u003c- function(...){}\n\nshinyApp(ui, server)\n```\n\n## Update\n\nAll inputs can be updated with `update_input`.\n\n```r\nlibrary(shiny)\nlibrary(litter)\n\nui \u003c- fluidPage(\n  theme = bslib::bs_theme(5L),\n  span(\"Type\", tags$code(\"error\"), \"below\"),\n  litTextInput(\n    name = \"txt\"\n  )\n)\n\nserver \u003c- function(input, output){\n  observeEvent(input$txt, {\n    if(input$txt$value == \"\"){\n      update_input(name = \"txt\", class = \"\")\n      return()\n    }\n\n    if(input$txt$value == \"error\"){\n      update_input(name = \"txt\", class = \"is-invalid\")\n      return()\n    }\n\n    update_input(name = \"txt\", class = \"is-valid\")\n  })\n}\n\nshinyApp(ui, server)\n```\n\n## Generate\n\nAn example of generating inputs with {litter}.\n\n```r\nlibrary(shiny)\nlibrary(litter)\n\nui \u003c- fluidPage(\n  theme = bslib::bs_theme(5L),\n  litRangeInput(\n    \"n\",\n    value = 5,\n    min = 3,\n    max = 10\n  ),\n  uiOutput(\"created\"),\n  verbatimTextOutput(\"result\")\n)\n\nserver \u003c- function(input, output, session) {\n  output$created \u003c- renderUI({\n    # we create n input\n    lapply(seq(input$n$value), \\(x){\n      div(\n        class = \"mb-1\",\n        span(\"Input\", x),\n        # all inputs have the same name\n        litTextInput(\n          name = \"text\",\n          n = x,\n          send_on_render = FALSE\n        )\n      )\n    })\n  })\n\n  output$result \u003c- renderPrint({\n    print(input$text)\n  })\n}\n\nshinyApp(ui, server, options = list(port = 3000L))\n```\n\n## Styling\n\nAll styling is taken from bslib's set theme as well as the `class` argument of \nall inputs.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FdevOpifex%2Flitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FdevOpifex%2Flitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FdevOpifex%2Flitter/lists"}