{"id":14068402,"url":"https://github.com/dgkf/scriptgloss","last_synced_at":"2025-04-14T00:57:30.241Z","repository":{"id":81661360,"uuid":"152449689","full_name":"dgkf/scriptgloss","owner":"dgkf","description":"dynamically reconstruct static code for shiny outputs","archived":false,"fork":false,"pushed_at":"2019-06-07T23:18:03.000Z","size":91,"stargazers_count":10,"open_issues_count":6,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-27T15:06:27.376Z","etag":null,"topics":["r","reproducibility","shiny","static-code-analysis"],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dgkf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-10-10T15:49:55.000Z","updated_at":"2023-08-28T16:05:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"7d0f02d4-eac9-4b2a-b96d-3859ecf5ca90","html_url":"https://github.com/dgkf/scriptgloss","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/dgkf%2Fscriptgloss","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgkf%2Fscriptgloss/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgkf%2Fscriptgloss/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgkf%2Fscriptgloss/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dgkf","download_url":"https://codeload.github.com/dgkf/scriptgloss/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248804786,"owners_count":21164131,"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","reproducibility","shiny","static-code-analysis"],"created_at":"2024-08-13T07:06:09.039Z","updated_at":"2025-04-14T00:57:30.214Z","avatar_url":"https://github.com/dgkf.png","language":"R","readme":"# scriptgloss\n\nReconstruct static code from shiny apps\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://user-images.githubusercontent.com/18220321/46750369-9f8aad00-cc6c-11e8-8852-eb0b37217c38.gif\"/\u003e\n\u003c/p\u003e\n\n\n`scriptgloss` exposes functionality for building static code to recreate outputs\nbuilt in a shiny context. Construct something in shiny and generate the code\nneeded to produce it without needing to trudge through the app code.\n\n# Installation\n\nFor now, due to a dependency on the `graph` package in Bioconductor by way of\n`CodeDepends`, this package will fail to install via the typical `devtools`\nmechanisms. Instead, please use `BiocManager` and follow any prompts to install\nthe package, pulling from Bioconductor when necessary. I'll be working to reduce\nthis impedence.\n\n```\ninstall.packages(\"BiocManager\") # R (\u003e3.5.0)\nBiocManager::install(\"dgkf/scriptgloss\")\n```\n\n\u003e**Developer Note**  \n\u003eThis was my first foray into advising installation via `BiocManager`. If you\n[run into issues, please report\nthem](https://github.com/dgkf/scriptgloss/issues) and I'll work to make the\ninstallation seamless until this dependency requirement has been resolved.\n\n# Getting Started\n\n## Start by building a `shiny` app\n\nLet's say we're building a shiny app to explore the `mtcars` dataset. We might\nstart with something like this:\n\n```r\nlibrary(shiny)\n\nui \u003c- fluidPage(\n  selectInput('x', 'x axis', choices = names(mtcars)),\n  selectInput('y', 'y axis', choices = names(mtcars)),\n  plotOutput('plot'))\n\nsrv \u003c- function(input, output, session) {\n  output$plot \u003c- renderPlot({\n    plot(x = mtcars[[input$x]], y = mtcars[[input$y]], \n      xlab = input$x, ylab = input$y)\n  })\n}\n\nshinyApp(ui, srv)\n```\n\nIf you run the code above, you'll see that it's quite simple; just two drop down\nmenus to pick an x and y variable which will update a plot to compare the two.\n\n## Adding code export elements\n\nIn order to add static code output, there are just a few small steps that need\nto be taken. \n\n1. The JavaScript dependencies need to be added to the webpage header. This can\nbe done easily by adding the UI element, `scriptglossJS()`.\n1. A UI button needs to be added to export the code. For this, `scriptgloss`\nprovides the functions `showCodeButton()` and `clipCodeButton()` for showing\ncode in a modal window or copying to clipboard respectively.\n1. An observer of the UI button needs to be added to prepare the code.\n\n\u003e### Adding a \"Show Code\" button\n\u003eA minimal example showing how you would use the `showCodeButton()` UI element.\nNot the most interesting code in the world, but operational!\n\n```r\nlibrary(shiny)\nlibrary(scriptgloss)\n\nui \u003c- fluidPage(\n  scriptglossJS(),\n  showCodeButton(\"show_code\"))\n\nsrv \u003c- function(input, output, session) {\n  # ui observer to display a modal code window when the button is pressed\n  observeEvent(input$show_code, show_code_modal(srv))\n}\n\nshinyApp(ui, srv)\n```\n\n\u003e### Adding a clipboard button to copy code\n\u003eA minimal example of how you would add a button to copy static code to the\nclipboard. Again, nothing too exciting, but hopefully enough to build it into\nyour own work.\n\n```r\nlibrary(shiny)\nlibrary(scriptgloss)\n\nui \u003c- fluidPage(\n  scriptglossJS(),\n  uiOutput('copy_code_btn'))\n\nsrv \u003c- function(input, output, session) {\n  # ui observer to copy code to the user's clipboard\n  output$copy_code_btn \u003c- renderUI(clipCodeButton(srv))\n}\n\nshinyApp(ui, srv)\n```\n\n## Reworking our `shiny` app to produce static code\n\nJust by following the steps above, we can quickly add a button to show off our\ncode!\n\n```r\nlibrary(shiny)\nlibrary(scriptgloss)\n\nui \u003c- fluidPage(\n  selectInput('x', 'x axis', choices = names(mtcars)),\n  selectInput('y', 'y axis', choices = names(mtcars)),\n  plotOutput('plot'),\n  # add our UI elements ... \n  scriptglossJS(),              # \u003c-- don't forget the JavaScript part!\n  showCodeButton(\"show_code\"),  # button to show code as a pop-up\n  uiOutput(\"clip_code_btn\"))    # button to copy to clipboard\n\nsrv \u003c- function(input, output, session) {\n  output$plot \u003c- renderPlot({\n    plot(x = mtcars[[input$x]], y = mtcars[[input$y]], \n      xlab = input$x, ylab = input$y)\n  })\n  \n  # observer for our modal button\n  observeEvent(input$show_code, show_code_modal(srv, \"plot\"))\n  \n  # button renderer for our copy-to-clipboard button\n  output$clip_code_btn \u003c- renderUI(clipCodeButton(text = get_code(srv, \"plot\")))\n}\n\nshinyApp(ui, srv)\n```\n\n# Acknowledgements\n\nEarly prototypes developed at Genentech. Many thanks to my employer for their \nencouragement and accommodation in allowing me to release this work publicly.\n","funding_links":[],"categories":["R"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgkf%2Fscriptgloss","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdgkf%2Fscriptgloss","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgkf%2Fscriptgloss/lists"}