### Check Node.js and npm Installation Source: https://github.com/rstudio/shiny/blob/main/srcts/README.md Verifies that Node.js and npm are installed correctly on your system by displaying their respective versions. ```bash node --version ``` ```bash npm --version ``` -------------------------------- ### Installing phantomjs on Ubuntu Source: https://github.com/rstudio/shiny/blob/main/smoketests/README.md Install the phantomjs dependency on Ubuntu systems using apt-get. ```bash apt-get install phantomjs ``` -------------------------------- ### Run runnable Shiny examples Source: https://github.com/rstudio/shiny/blob/main/NEWS.md Most code examples now include a runnable `shinyApp()` instance for direct execution and testing. ```R shinyApp() ``` -------------------------------- ### List Available Shiny Examples Source: https://github.com/rstudio/shiny/blob/main/README.md Loads the Shiny library and lists all available pre-packaged example applications. This helps users discover and explore different Shiny app functionalities. ```r library(shiny) # Lists more prepackaged examples runExample() ``` -------------------------------- ### Run Shiny Example App Source: https://github.com/rstudio/shiny/blob/main/README.md Loads the Shiny library and runs a pre-packaged example application named '06_tabsets'. This is useful for quickly seeing Shiny in action. ```r library(shiny) # Launches an app, with the app's source code included runExample("06_tabsets") ``` -------------------------------- ### Installing phantomjs on macOS Source: https://github.com/rstudio/shiny/blob/main/smoketests/README.md Install the phantomjs dependency on macOS systems using homebrew. ```bash brew install phantomjs ``` -------------------------------- ### R Stack Trace Example Source: https://github.com/rstudio/shiny/wiki/Stack-traces-in-R A basic R code example that generates a stack trace, showing function calls and line numbers. ```r 1. foo <- function() { 2. stop("boom") 3. } 4. foo() ``` -------------------------------- ### Shiny Stack Trace Example Source: https://github.com/rstudio/shiny/wiki/Stack-traces-in-R Shows how Shiny reformats a stack trace to display function names and offset source references for improved readability. ```r 12: stop 11: foo [~/foo.R#2] ``` -------------------------------- ### Install Shiny Package Source: https://github.com/rstudio/shiny/blob/main/README.md Installs the stable version of the Shiny package from CRAN. This is the primary method for obtaining the package. ```r install.packages("shiny") ``` -------------------------------- ### Install Exact Package Versions with npm ci Source: https://github.com/rstudio/shiny/blob/main/srcts/README.md Installs dependencies precisely as defined in `package-lock.json` to ensure reproducible builds across different environments. ```bash npm ci ``` -------------------------------- ### Manual Instrumentation with Deep Stack Traces Source: https://github.com/rstudio/shiny/wiki/Stack-traces-in-R Demonstrates how `..stacktraceoff..` and `..stacktraceon..` are used in an asynchronous context with `future` and promise chaining. This example highlights the challenge of paired instrumentation across different stack traces. ```r read_data_async <- function(user_provided_callback) { ..stacktraceoff..( future({ ... }) %...>% { ..stacktraceon..(user_provided_callback(.)) } ) } ``` -------------------------------- ### Install Specific Shiny Version Source: https://github.com/rstudio/shiny/blob/main/NEWS.md Install a specific older version of Shiny using the `install_version` function from the `devtools` package. Ensure `devtools` is installed first. ```r # Install devtools if you don't already have it: install.package("devtools") # Install the last version of Shiny prior to 0.11 devtools::install_version("shiny", "0.10.2.2") ``` -------------------------------- ### Install npm Packages for Shiny Repository Source: https://github.com/rstudio/shiny/blob/main/srcts/README.md Installs all necessary npm packages for the Shiny project when located in the root `rstudio/shiny` directory. ```bash # Sitting in `rstudio/shiny` repo npm install ``` -------------------------------- ### Install Shiny TypeScript Definitions Source: https://github.com/rstudio/shiny/blob/main/srcts/README.md Installs the latest stable Shiny TypeScript definitions from GitHub. Match the GitHub tag to your Shiny CRAN release. Select the closest matching version if prompted for `@types/jquery`. ```bash npm install https://github.com/rstudio/shiny#v1.11.0 --save-dev ``` -------------------------------- ### Install Latest Shiny from GitHub Source: https://github.com/rstudio/shiny/wiki/Writing-Good-Bug-Reports Install the most recent version of Shiny directly from its GitHub repository using the devtools package. This is useful for checking if an issue has already been fixed on the master branch. ```r devtools::install_github("rstudio/shiny") ``` -------------------------------- ### Basic Shiny App Template Source: https://github.com/rstudio/shiny/wiki/Creating-a-Reproducible-Example A minimal template for a Shiny application. This can be used as a starting point for constructing new Shiny applications or reproducible examples. ```r shinyApp( ui = fluidPage( numericInput("n", "n", 1), plotOutput("plot") ), server = function(input, output, session) { output$plot <- renderPlot( plot(head(cars, input$n)) ) } ) ``` -------------------------------- ### Install @posit/shiny Source: https://github.com/rstudio/shiny/blob/main/README-npm.md Install the @posit/shiny npm package to add TypeScript type definitions for Shiny's client-side JavaScript libraries to your project. ```bash npm install @posit/shiny ``` -------------------------------- ### Add or Upgrade npm Packages Source: https://github.com/rstudio/shiny/blob/main/srcts/README.md Installs a new package and saves it as a development dependency. This also updates `package-lock.json`. Run `npm ci` to sync local packages. ```bash npm install --save-dev [packagename] ``` -------------------------------- ### Update Node.js to the Latest Stable Version Source: https://github.com/rstudio/shiny/blob/main/srcts/README.md Uses `npx` to install the latest stable version of Node.js. This helps manage Node.js versions without manual detection. ```bash # Update to the latest stable node version npx n stable ``` ```bash # View installed versions npx n ls ``` -------------------------------- ### TypeScript Record Annotation Example Source: https://github.com/rstudio/shiny/blob/main/srcts/README.md Annotates a record with string keys and number values, and demonstrates extending with static keys. ```typescript const x: {[key: string]: number} = {a: 4} const x: {known: string, [key: string]: number} = {known: "yes", a: 4} ``` -------------------------------- ### Restore-aware textInput Function Source: https://github.com/rstudio/shiny/wiki/Bookmarkable-state Example of a restore-aware input function that uses `restoreInput` to potentially restore its value from a restore context. The `restoreContext` parameter can be set to NULL to opt out of restoration. ```R textInput <- function(inputId, label, value = "", width = NULL, placeholder = NULL, restoreContext = getDefaultRestoreContext()) { value <- restoreInput(id = inputId, defaultValue = value, restoreContext = restoreContext) ... } ``` -------------------------------- ### Run npm build script Source: https://github.com/rstudio/shiny/blob/main/srcts/README.md Builds the shiny.js and shiny.min.js files in inst/www/shared, including sourcemaps. ```bash npm run build ``` -------------------------------- ### Custom State Callbacks for Saving and Restoring Source: https://github.com/rstudio/shiny/wiki/Bookmarkable-state Demonstrates how to define custom callbacks for saving application state and restoring it using `setStateCallbacks`. This is used for state not automatically handled by input values. ```R server <- function(input, output, session) { excludedPoints <- c() makeReactiveBinding("excludedPoints") setStateCallbacks( # need better function name onSave = function() { # No need to save input$xxx, it's done automatically # User returns (named) values and files somehow, API TBD. # For this strawman proposal, just return list list( values = list( excludedPoints = excludedPoints ) ) }, onRestore = function(restoreContext) { excludedPoints <<- restoreContext$values$excludedPoints } ) ... } ``` -------------------------------- ### Server: Implement Download Handler Source: https://github.com/rstudio/shiny/blob/main/inst/examples/10_download/Readme.md The `downloadHandler()` function in the server logic defines the file to be downloaded. It requires `filename` and `content` arguments. The `filename` specifies the name of the file to be downloaded, and `content` is a function that generates the file's content. ```r output$report <- downloadHandler( filename = function() { paste("report-", Sys.Date(), ".csv", sep = "") }, content = function(file) { write.csv( YourData(), file, row.names = FALSE) } ) ``` -------------------------------- ### Using useBusyIndicators Source: https://github.com/rstudio/shiny/blob/main/tests/testthat/_snaps/busy-indication.md Demonstrates the basic usage of `useBusyIndicators` to enable spinners and pulses. Shows how to disable spinners or pulses individually or both. ```R tagList(useBusyIndicators(), useBusyIndicators(spinners = FALSE), useBusyIndicators(pulse = FALSE), useBusyIndicators(spinners = FALSE, pulse = FALSE), ) ``` -------------------------------- ### Opt-in to Bootstrap 5 Theming Source: https://github.com/rstudio/shiny/blob/main/NEWS.md To use Bootstrap 5, provide `bslib::bs_theme(version = 5)` to the `theme` argument of a page layout function like `fluidPage()` or `navbarPage()`. ```R bslib::bs_theme(version = 5) ``` -------------------------------- ### Handling Quosures with installExprFunction Source: https://github.com/rstudio/shiny/blob/main/NEWS.md When `quoted = TRUE`, `installExprFunction()` and `exprToFunction()` can handle quosures. This allows `render`-functions to embed environment and quoted information within a quosure passed to the function. ```R installExprFunction(expr, name, quoted = TRUE) ``` -------------------------------- ### Dynamic Theming with bslib Source: https://github.com/rstudio/shiny/blob/main/NEWS.md Dynamically update the page's theme using session$setCurrentTheme() and session$getCurrentTheme(). This is useful for features like adding a dark mode switch. ```R session$setCurrentTheme(bslib::bs_theme(bootswatch = "darkly")) ``` -------------------------------- ### Basic Shiny App with Error Source: https://github.com/rstudio/shiny/wiki/Creating-a-Reproducible-Example This is an example of a Shiny application that demonstrates an error. It can be used to reproduce the 'non-numeric argument to binary operator' issue. ```r shinyApp( ui = fluidPage( selectInput("n", "N", 1:10), plotOutput("plot") ), server = function(input, output, session) { output$plot <- renderPlot({ n <- input$n * 2 plot(head(cars, n)) }) } ) ``` -------------------------------- ### UI: Add Download Button Source: https://github.com/rstudio/shiny/blob/main/inst/examples/10_download/Readme.md Use `downloadButton()` to create a button in the UI that triggers a file download. This function requires an ID that will be used to link it to the server-side handler. ```r downloadButton("report", "Download report") ``` -------------------------------- ### Shiny downloadLink (enabled = TRUE) Source: https://github.com/rstudio/shiny/blob/main/tests/testthat/_snaps/downloadButton.md Creates a download link that is explicitly enabled. This ensures the link is active and ready for download. ```R downloadLink("dl", "Download", enabled = TRUE) ``` -------------------------------- ### R Code to Generate a Data Frame Source: https://github.com/rstudio/shiny/wiki/Creating-a-Reproducible-Example This R code snippet defines a simple data frame named 'mydata'. It's useful for creating sample data within a reproducible example. ```r mydata <- data.frame(x = 1:5, y = c("a", "b", "c", "d", "e")) ``` -------------------------------- ### TabPanel with Disabled Tab and Shiny.tag Input Source: https://github.com/rstudio/shiny/blob/main/tests/testthat/_snaps/tabPanel.md Illustrates a tabPanel structure where one tab is explicitly disabled and another uses a Shiny.tag input. This setup is for scenarios requiring a non-selectable tab or specific tag handling. ```html
A div
a
b
c
``` -------------------------------- ### Control www directory display in Showcase mode Source: https://github.com/rstudio/shiny/blob/main/NEWS.md Set `IncludeWWW: False` in the Description file to prevent the `.js`, `.html`, and `.css` files in the `www` directory from being displayed in Showcase mode. ```text IncludeWWW: False ``` -------------------------------- ### Basic actionButton Source: https://github.com/rstudio/shiny/blob/main/tests/testthat/_snaps/actionButton.md Creates a standard action button with a label. Use this for simple button interactions. ```r actionButton("foo", "Click me") ``` -------------------------------- ### Configure Shiny App Host and Port Source: https://github.com/rstudio/shiny/wiki/Windows-Testing Run a Shiny application with specific host and port options to ensure accessibility from a Windows VM. Use '0.0.0.0' for the host to allow connections from any network interface. ```r shinyApp(ui = ui, server = server, options = list(host = "0.0.0.0", port = 8080)) ``` -------------------------------- ### Shiny downloadButton (enabled = TRUE) Source: https://github.com/rstudio/shiny/blob/main/tests/testthat/_snaps/downloadButton.md Creates a download button that is explicitly enabled. This ensures the button is active and ready for download. ```R downloadButton("dl", "Download", enabled = TRUE) ``` -------------------------------- ### Basic actionLink Source: https://github.com/rstudio/shiny/blob/main/tests/testthat/_snaps/actionButton.md Creates a clickable link that behaves like an action button. Suitable for inline actions. ```r actionLink("foo", "Click me") ``` -------------------------------- ### Shiny downloadLink (enabled = 'auto') Source: https://github.com/rstudio/shiny/blob/main/tests/testthat/_snaps/downloadButton.md Creates a download link with the default 'auto' enabled state. The link will be disabled if no download is available. ```R downloadLink("dl", "Download") ``` -------------------------------- ### Configure Progress Indicator Style Source: https://github.com/rstudio/shiny/blob/main/NEWS.md Set the style for progress indicators. Use `style = "old"` to revert to the previous styling, which might be necessary if you have custom CSS applied. ```r shinyOptions(progress.style = "old") ``` -------------------------------- ### Running Comparison Tests Source: https://github.com/rstudio/shiny/blob/main/smoketests/README.md Execute R applications and compare their stdout/stderr output against existing R.out.save files. Any discrepancies are reported as test failures. ```bash Rscript test.R ``` -------------------------------- ### Basic tabPanel with String Input Source: https://github.com/rstudio/shiny/blob/main/tests/testthat/_snaps/tabPanel.md Demonstrates a basic tabPanel structure where the input is a simple string. This is useful for creating straightforward tabbed navigation. ```html
a
b
c
``` -------------------------------- ### Update htmlTemplate documentation Source: https://github.com/rstudio/shiny/blob/main/NEWS.md Documentation for `htmlTemplate` has been updated. ```R htmlTemplate ``` -------------------------------- ### Initialize Button Widget with Icon Source: https://github.com/rstudio/shiny/blob/main/inst/www/shared/jqueryui/index.html Initializes the button widget with an icon and hides the label. ```javascript $( "#button-icon" ).button({ icon: "ui-icon-gear", showLabel: false }); ``` -------------------------------- ### Shiny downloadButton (enabled = 'auto') Source: https://github.com/rstudio/shiny/blob/main/tests/testthat/_snaps/downloadButton.md Creates a download button with the default 'auto' enabled state. The button will be disabled if no download is available. ```R downloadButton("dl", "Download") ``` -------------------------------- ### Linear Stack Trace Tree Source: https://github.com/rstudio/shiny/wiki/Stack-traces-in-R Demonstrates a simple linear stack trace where each function call directly leads to the next without delayed evaluation. ```r a <- function() { lobstr::cst() } b <- function() { a() } c <- function() { b() } ``` -------------------------------- ### HTML5 pushState support for Shiny Apps Source: https://github.com/rstudio/shiny/blob/main/NEWS.md Enables pseudo-navigation within Shiny applications using HTML5's pushState API. Refer to ?updateQueryString and ?getQueryString for details. ```r updateQueryString("?new=query") ``` -------------------------------- ### Send custom binary data to client Source: https://github.com/rstudio/shiny/blob/main/NEWS.md Use `session$sendBinaryMessage(type, message)` to send custom binary data from the server to the client. ```R session$sendBinaryMessage(type, message) ``` -------------------------------- ### Initialize Autocomplete Widget Source: https://github.com/rstudio/shiny/blob/main/inst/www/shared/jqueryui/index.html Initializes the autocomplete widget with a predefined list of tags. ```javascript var availableTags = [ "ActionScript", "AppleScript", "Asp", "BASIC", "C", "C++", "Clojure", "COBOL", "ColdFusion", "Erlang", "Fortran", "Groovy", "Haskell", "Java", "JavaScript", "Lisp", "Perl", "PHP", "Python", "Ruby", "Scala", "Scheme" ]; $( "#autocomplete" ).autocomplete({ source: availableTags }); ``` -------------------------------- ### Using Font Awesome Icons Source: https://github.com/rstudio/shiny/blob/main/NEWS.md Use `icon(lib="fontawesome")` to leverage the `{fontawesome}` package for easier access to the latest Font Awesome icons. ```R icon(lib="fontawesome") ``` -------------------------------- ### tabPanel with bslib Tags (Tabs) Source: https://github.com/rstudio/shiny/blob/main/tests/testthat/_snaps/tabPanel.md Illustrates the HTML output for a tabPanel using bslib tags, resulting in Bootstrap 5 compatible tab styling. ```html
a
b
c
``` -------------------------------- ### Running Snapshot Tests Source: https://github.com/rstudio/shiny/blob/main/smoketests/README.md Execute R applications and capture their stdout/stderr output using phantomjs. The output is saved to an R.out.save file for later comparison. ```bash Rscript snapshot.R ``` -------------------------------- ### Shiny downloadButton (enabled = FALSE) Source: https://github.com/rstudio/shiny/blob/main/tests/testthat/_snaps/downloadButton.md Creates a download button that is explicitly disabled. This is useful when a download is not yet ready or should not be offered. ```R downloadButton("dl", "Download", enabled = FALSE) ``` -------------------------------- ### Create and Inspect reactiveValues Source: https://github.com/rstudio/shiny/blob/main/tests/testthat/print-reactiveValues.txt Demonstrates how to create a reactiveValues object and inspect its contents. reactiveValues are fundamental for managing state in Shiny applications. ```R x <- reactiveValues(x = 1, y = 2, z = 3) x ``` -------------------------------- ### Shiny downloadLink (enabled = FALSE) Source: https://github.com/rstudio/shiny/blob/main/tests/testthat/_snaps/downloadButton.md Creates a download link that is explicitly disabled. This is useful when a download is not yet ready or should not be offered. ```R downloadLink("dl", "Download", enabled = FALSE) ``` -------------------------------- ### Initialize Menu Widget Source: https://github.com/rstudio/shiny/blob/main/inst/www/shared/jqueryui/index.html Initializes the menu widget on an element with the ID 'menu'. ```javascript $( "#menu" ).menu(); ``` -------------------------------- ### Handle missing files in downloadHandler Source: https://github.com/rstudio/shiny/blob/main/NEWS.md Modified `downloadHandler()` to return a 404 error code instead of opening an empty browser window when the file is not present. ```R downloadHandler() ``` -------------------------------- ### Automatic selection in navbarPage with navbarMenu Source: https://github.com/rstudio/shiny/blob/main/NEWS.md Resolved an issue where `navbarPage()` did not automatically select an item when `navbarMenu()` was the first item. ```R navbarPage() ``` ```R navbarMenu() ``` -------------------------------- ### Code diagnostics for UI/Server files Source: https://github.com/rstudio/shiny/blob/main/NEWS.md Shiny now provides code diagnostics for `ui.R`, `server.R`, `app.R`, or `global.R` to identify missing commas, extra commas, and unmatched braces, parens, or brackets. ```R ui.R, server.R, app.R, or global.R ``` -------------------------------- ### Initialize Progressbar Widget Source: https://github.com/rstudio/shiny/blob/main/inst/www/shared/jqueryui/index.html Initializes the progressbar widget with a value of 20. ```javascript $( "#progressbar" ).progressbar({ value: 20 }); ``` -------------------------------- ### Dynamic UI with htmltools::htmlDependency Source: https://github.com/rstudio/shiny/blob/main/NEWS.md Demonstrates the correct rendering of htmltools::htmlDependency() with a list of script attributes in dynamic UI contexts. Requires htmltools v0.5.1 or later. ```R htmltools::htmlDependency(name = "my-dep", version = "1.0.0", src = "./www", script = list(list(src = "file1.js"), list(src = "file2.js"))) ``` -------------------------------- ### Initialize Tooltip Widget Source: https://github.com/rstudio/shiny/blob/main/inst/www/shared/jqueryui/index.html Initializes the tooltip widget on an element with the ID 'tooltip'. ```javascript $( "#tooltip" ).tooltip(); ``` -------------------------------- ### Using rlang::list2 for Tab Panels Source: https://github.com/rstudio/shiny/blob/main/NEWS.md Replace `list(...)` with `rlang::list2(...)` to enable trailing commas and use `!!!` for splicing lists of `tabPanel` arguments into consumers like `tabsetPanel()` or `navbarPage()`. ```R tabs <- list(tabPanel("A", "a"), tabPanel("B", "b")); navbarPage(!!!tabs) ```