### 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