From f85e8e7904fb982cbb89ace1be5f90411ba648a9 Mon Sep 17 00:00:00 2001 From: skaltman Date: Wed, 3 Jan 2024 14:36:13 -0800 Subject: [PATCH 01/18] update 01_hello --- inst/examples/01_hello/app.R | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/inst/examples/01_hello/app.R b/inst/examples/01_hello/app.R index 887c50576d..a098a7b422 100644 --- a/inst/examples/01_hello/app.R +++ b/inst/examples/01_hello/app.R @@ -1,34 +1,23 @@ library(shiny) +library(bslib) # Define UI for app that draws a histogram ---- -ui <- fluidPage( +ui <- page_sidebar( # App title ---- - titlePanel("Hello Shiny!"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- - sidebarPanel( - + title = "Hello Shiny!", + # Sidebar panel for inputs ---- + sidebar = + sidebar( # Input: Slider for the number of bins ---- sliderInput(inputId = "bins", label = "Number of bins:", min = 1, max = 50, value = 30) - ), - - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Histogram ---- - plotOutput(outputId = "distPlot") - - ) - ) + # Output: Histogram ---- + plotOutput(outputId = "distPlot") ) # Define server logic required to draw a histogram ---- From 8eee8ddaf6bd133dbdefe7e70102847d5a08ec39 Mon Sep 17 00:00:00 2001 From: Garrett Grolemund Date: Thu, 4 Jan 2024 11:20:42 -0600 Subject: [PATCH 02/18] Updates 06_tabsets example to use bslib --- inst/examples/06_tabsets/Readme.md | 2 +- inst/examples/06_tabsets/app.R | 75 ++++++++++++++---------------- 2 files changed, 37 insertions(+), 40 deletions(-) diff --git a/inst/examples/06_tabsets/Readme.md b/inst/examples/06_tabsets/Readme.md index c548d306d0..5dac839728 100644 --- a/inst/examples/06_tabsets/Readme.md +++ b/inst/examples/06_tabsets/Readme.md @@ -1,4 +1,4 @@ -This example demonstrates the `tabsetPanel` and `tabPanel` widgets. +This example demonstrates the `navset_*` and `nav_panel` widgets from the `bslib` package. Notice that outputs that are not visible are not re-evaluated until they become visible. Try this: diff --git a/inst/examples/06_tabsets/app.R b/inst/examples/06_tabsets/app.R index e1b89d6644..6059bc35f2 100644 --- a/inst/examples/06_tabsets/app.R +++ b/inst/examples/06_tabsets/app.R @@ -1,47 +1,44 @@ library(shiny) +library(bslib) # Define UI for random distribution app ---- -ui <- fluidPage( +# Sidebar layout with input and output definitions ---- +ui <- page_sidebar( # App title ---- - titlePanel("Tabsets"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- - sidebarPanel( - - # Input: Select the random distribution type ---- - radioButtons("dist", "Distribution type:", - c("Normal" = "norm", - "Uniform" = "unif", - "Log-normal" = "lnorm", - "Exponential" = "exp")), - - # br() element to introduce extra vertical spacing ---- - br(), - - # Input: Slider for the number of observations to generate ---- - sliderInput("n", - "Number of observations:", - value = 500, - min = 1, - max = 1000) - - ), - - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Tabset w/ plot, summary, and table ---- - tabsetPanel(type = "tabs", - tabPanel("Plot", plotOutput("plot")), - tabPanel("Summary", verbatimTextOutput("summary")), - tabPanel("Table", tableOutput("table")) - ) - - ) + title ="Tabsets", + + # Sidebar panel for inputs ---- + sidebar = sidebar( + + # Input: Select the random distribution type ---- + radioButtons("dist", "Distribution type:", + c("Normal" = "norm", + "Uniform" = "unif", + "Log-normal" = "lnorm", + "Exponential" = "exp")), + # br() element to introduce extra vertical spacing ---- + br(), + # Input: Slider for the number of observations to generate ---- + sliderInput("n", + "Number of observations:", + value = 500, + min = 1, + max = 1000) + ), + + # Main panel for displaying outputs ---- + # Output: A tabset that combines three panels ---- + navset_underline( + + # Panel with plot ---- + nav_panel("Plot", plotOutput("plot")), + + # Panel with summary ---- + nav_panel("Summary", verbatimTextOutput("summary")), + + # Panel with table ---- + nav_panel("Table", tableOutput("table")) ) ) From 43bf4af42488f7d49e639106b7eff79734a2e723 Mon Sep 17 00:00:00 2001 From: Garrett Grolemund Date: Thu, 4 Jan 2024 11:26:46 -0600 Subject: [PATCH 03/18] Pre-emptively adds legacy versions of all of the original examples --- inst/examples/01_hello_legacy/DESCRIPTION | 7 ++ inst/examples/01_hello_legacy/Readme.md | 3 + inst/examples/01_hello_legacy/app.R | 59 ++++++++++ inst/examples/02_text_legacy/DESCRIPTION | 8 ++ inst/examples/02_text_legacy/Readme.md | 1 + inst/examples/02_text_legacy/app.R | 64 +++++++++++ .../examples/03_reactivity_legacy/DESCRIPTION | 7 ++ inst/examples/03_reactivity_legacy/Readme.md | 5 + inst/examples/03_reactivity_legacy/app.R | 102 ++++++++++++++++++ inst/examples/04_mpg_legacy/DESCRIPTION | 7 ++ inst/examples/04_mpg_legacy/Readme.md | 4 + inst/examples/04_mpg_legacy/app.R | 75 +++++++++++++ inst/examples/05_sliders_legacy/DESCRIPTION | 7 ++ inst/examples/05_sliders_legacy/Readme.md | 3 + inst/examples/05_sliders_legacy/app.R | 86 +++++++++++++++ inst/examples/06_tabsets_legacy/DESCRIPTION | 7 ++ inst/examples/06_tabsets_legacy/Readme.md | 9 ++ inst/examples/06_tabsets_legacy/app.R | 92 ++++++++++++++++ inst/examples/07_widgets_legacy/DESCRIPTION | 7 ++ inst/examples/07_widgets_legacy/Readme.md | 1 + inst/examples/07_widgets_legacy/app.R | 82 ++++++++++++++ inst/examples/08_html_legacy/DESCRIPTION | 7 ++ inst/examples/08_html_legacy/Readme.md | 1 + inst/examples/08_html_legacy/app.R | 47 ++++++++ inst/examples/08_html_legacy/www/index.html | 41 +++++++ inst/examples/09_upload_legacy/DESCRIPTION | 7 ++ inst/examples/09_upload_legacy/Readme.md | 3 + inst/examples/09_upload_legacy/app.R | 92 ++++++++++++++++ inst/examples/10_download_legacy/DESCRIPTION | 7 ++ inst/examples/10_download_legacy/Readme.md | 2 + inst/examples/10_download_legacy/app.R | 63 +++++++++++ inst/examples/11_timer_legacy/DESCRIPTION | 7 ++ inst/examples/11_timer_legacy/Readme.md | 4 + inst/examples/11_timer_legacy/app.R | 21 ++++ 34 files changed, 938 insertions(+) create mode 100644 inst/examples/01_hello_legacy/DESCRIPTION create mode 100644 inst/examples/01_hello_legacy/Readme.md create mode 100644 inst/examples/01_hello_legacy/app.R create mode 100644 inst/examples/02_text_legacy/DESCRIPTION create mode 100644 inst/examples/02_text_legacy/Readme.md create mode 100644 inst/examples/02_text_legacy/app.R create mode 100644 inst/examples/03_reactivity_legacy/DESCRIPTION create mode 100644 inst/examples/03_reactivity_legacy/Readme.md create mode 100644 inst/examples/03_reactivity_legacy/app.R create mode 100644 inst/examples/04_mpg_legacy/DESCRIPTION create mode 100644 inst/examples/04_mpg_legacy/Readme.md create mode 100644 inst/examples/04_mpg_legacy/app.R create mode 100644 inst/examples/05_sliders_legacy/DESCRIPTION create mode 100644 inst/examples/05_sliders_legacy/Readme.md create mode 100644 inst/examples/05_sliders_legacy/app.R create mode 100644 inst/examples/06_tabsets_legacy/DESCRIPTION create mode 100644 inst/examples/06_tabsets_legacy/Readme.md create mode 100644 inst/examples/06_tabsets_legacy/app.R create mode 100644 inst/examples/07_widgets_legacy/DESCRIPTION create mode 100644 inst/examples/07_widgets_legacy/Readme.md create mode 100644 inst/examples/07_widgets_legacy/app.R create mode 100644 inst/examples/08_html_legacy/DESCRIPTION create mode 100644 inst/examples/08_html_legacy/Readme.md create mode 100644 inst/examples/08_html_legacy/app.R create mode 100644 inst/examples/08_html_legacy/www/index.html create mode 100644 inst/examples/09_upload_legacy/DESCRIPTION create mode 100644 inst/examples/09_upload_legacy/Readme.md create mode 100644 inst/examples/09_upload_legacy/app.R create mode 100644 inst/examples/10_download_legacy/DESCRIPTION create mode 100644 inst/examples/10_download_legacy/Readme.md create mode 100644 inst/examples/10_download_legacy/app.R create mode 100644 inst/examples/11_timer_legacy/DESCRIPTION create mode 100644 inst/examples/11_timer_legacy/Readme.md create mode 100644 inst/examples/11_timer_legacy/app.R diff --git a/inst/examples/01_hello_legacy/DESCRIPTION b/inst/examples/01_hello_legacy/DESCRIPTION new file mode 100644 index 0000000000..fd1d5a5280 --- /dev/null +++ b/inst/examples/01_hello_legacy/DESCRIPTION @@ -0,0 +1,7 @@ +Title: Hello Shiny! +Author: RStudio, Inc. +AuthorUrl: http://www.rstudio.com/ +License: MIT +DisplayMode: Showcase +Tags: getting-started +Type: Shiny diff --git a/inst/examples/01_hello_legacy/Readme.md b/inst/examples/01_hello_legacy/Readme.md new file mode 100644 index 0000000000..a2450acc16 --- /dev/null +++ b/inst/examples/01_hello_legacy/Readme.md @@ -0,0 +1,3 @@ +This small Shiny application demonstrates Shiny's automatic UI updates. + +Move the *Number of bins* slider and notice how the `renderPlot` expression is automatically re-evaluated when its dependant, `input$bins`, changes, causing a histogram with a new number of bins to be rendered. diff --git a/inst/examples/01_hello_legacy/app.R b/inst/examples/01_hello_legacy/app.R new file mode 100644 index 0000000000..887c50576d --- /dev/null +++ b/inst/examples/01_hello_legacy/app.R @@ -0,0 +1,59 @@ +library(shiny) + +# Define UI for app that draws a histogram ---- +ui <- fluidPage( + + # App title ---- + titlePanel("Hello Shiny!"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- + sidebarPanel( + + # Input: Slider for the number of bins ---- + sliderInput(inputId = "bins", + label = "Number of bins:", + min = 1, + max = 50, + value = 30) + + ), + + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Histogram ---- + plotOutput(outputId = "distPlot") + + ) + ) +) + +# Define server logic required to draw a histogram ---- +server <- function(input, output) { + + # Histogram of the Old Faithful Geyser Data ---- + # with requested number of bins + # This expression that generates a histogram is wrapped in a call + # to renderPlot to indicate that: + # + # 1. It is "reactive" and therefore should be automatically + # re-executed when inputs (input$bins) change + # 2. Its output type is a plot + output$distPlot <- renderPlot({ + + x <- faithful$waiting + bins <- seq(min(x), max(x), length.out = input$bins + 1) + + hist(x, breaks = bins, col = "#75AADB", border = "white", + xlab = "Waiting time to next eruption (in mins)", + main = "Histogram of waiting times") + + }) + +} + +# Create Shiny app ---- +shinyApp(ui = ui, server = server) diff --git a/inst/examples/02_text_legacy/DESCRIPTION b/inst/examples/02_text_legacy/DESCRIPTION new file mode 100644 index 0000000000..8f62a976a7 --- /dev/null +++ b/inst/examples/02_text_legacy/DESCRIPTION @@ -0,0 +1,8 @@ +Title: Shiny Text +Author: RStudio, Inc. +AuthorUrl: http://www.rstudio.com/ +License: MIT +DisplayMode: Showcase +Tags: getting-started +Type: Shiny + diff --git a/inst/examples/02_text_legacy/Readme.md b/inst/examples/02_text_legacy/Readme.md new file mode 100644 index 0000000000..7aa04e5ed9 --- /dev/null +++ b/inst/examples/02_text_legacy/Readme.md @@ -0,0 +1 @@ +This example demonstrates output of raw text from R using the `renderPrint` function in `server` and the `verbatimTextOutput` function in `ui`. In this case, a textual summary of the data is shown using R's built-in `summary` function. diff --git a/inst/examples/02_text_legacy/app.R b/inst/examples/02_text_legacy/app.R new file mode 100644 index 0000000000..9aff1e850c --- /dev/null +++ b/inst/examples/02_text_legacy/app.R @@ -0,0 +1,64 @@ +library(shiny) + +# Define UI for dataset viewer app ---- +ui <- fluidPage( + + # App title ---- + titlePanel("Shiny Text"), + + # Sidebar layout with a input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- + sidebarPanel( + + # Input: Selector for choosing dataset ---- + selectInput(inputId = "dataset", + label = "Choose a dataset:", + choices = c("rock", "pressure", "cars")), + + # Input: Numeric entry for number of obs to view ---- + numericInput(inputId = "obs", + label = "Number of observations to view:", + value = 10) + ), + + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Verbatim text for data summary ---- + verbatimTextOutput("summary"), + + # Output: HTML table with requested number of observations ---- + tableOutput("view") + + ) + ) +) + +# Define server logic to summarize and view selected dataset ---- +server <- function(input, output) { + + # Return the requested dataset ---- + datasetInput <- reactive({ + switch(input$dataset, + "rock" = rock, + "pressure" = pressure, + "cars" = cars) + }) + + # Generate a summary of the dataset ---- + output$summary <- renderPrint({ + dataset <- datasetInput() + summary(dataset) + }) + + # Show the first "n" observations ---- + output$view <- renderTable({ + head(datasetInput(), n = input$obs) + }) + +} + +# Create Shiny app ---- +shinyApp(ui = ui, server = server) diff --git a/inst/examples/03_reactivity_legacy/DESCRIPTION b/inst/examples/03_reactivity_legacy/DESCRIPTION new file mode 100644 index 0000000000..01db04d4ad --- /dev/null +++ b/inst/examples/03_reactivity_legacy/DESCRIPTION @@ -0,0 +1,7 @@ +Title: Reactivity +Author: RStudio, Inc. +AuthorUrl: http://www.rstudio.com/ +License: MIT +DisplayMode: Showcase +Tags: getting-started +Type: Shiny diff --git a/inst/examples/03_reactivity_legacy/Readme.md b/inst/examples/03_reactivity_legacy/Readme.md new file mode 100644 index 0000000000..8eaee27ef6 --- /dev/null +++ b/inst/examples/03_reactivity_legacy/Readme.md @@ -0,0 +1,5 @@ +This example demonstrates a core feature of Shiny: **reactivity**. In the `server` function, a reactive called `datasetInput` is declared. + +Notice that the reactive expression depends on the input expression `input$dataset`, and that it's used by two output expressions: `output$summary` and `output$view`. Try changing the dataset (using *Choose a dataset*) while looking at the reactive and then at the outputs; you will see first the reactive and then its dependencies flash. + +Notice also that the reactive expression doesn't just update whenever anything changes--only the inputs it depends on will trigger an update. Change the "Caption" field and notice how only the `output$caption` expression is re-evaluated; the reactive and its dependents are left alone. diff --git a/inst/examples/03_reactivity_legacy/app.R b/inst/examples/03_reactivity_legacy/app.R new file mode 100644 index 0000000000..393ebfe619 --- /dev/null +++ b/inst/examples/03_reactivity_legacy/app.R @@ -0,0 +1,102 @@ +library(shiny) + +# Define UI for dataset viewer app ---- +ui <- fluidPage( + + # App title ---- + titlePanel("Reactivity"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- + sidebarPanel( + + # Input: Text for providing a caption ---- + # Note: Changes made to the caption in the textInput control + # are updated in the output area immediately as you type + textInput(inputId = "caption", + label = "Caption:", + value = "Data Summary"), + + # Input: Selector for choosing dataset ---- + selectInput(inputId = "dataset", + label = "Choose a dataset:", + choices = c("rock", "pressure", "cars")), + + # Input: Numeric entry for number of obs to view ---- + numericInput(inputId = "obs", + label = "Number of observations to view:", + value = 10) + + ), + + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Formatted text for caption ---- + h3(textOutput("caption", container = span)), + + # Output: Verbatim text for data summary ---- + verbatimTextOutput("summary"), + + # Output: HTML table with requested number of observations ---- + tableOutput("view") + + ) + ) +) + +# Define server logic to summarize and view selected dataset ---- +server <- function(input, output) { + + # Return the requested dataset ---- + # By declaring datasetInput as a reactive expression we ensure + # that: + # + # 1. It is only called when the inputs it depends on changes + # 2. The computation and result are shared by all the callers, + # i.e. it only executes a single time + datasetInput <- reactive({ + switch(input$dataset, + "rock" = rock, + "pressure" = pressure, + "cars" = cars) + }) + + # Create caption ---- + # The output$caption is computed based on a reactive expression + # that returns input$caption. When the user changes the + # "caption" field: + # + # 1. This function is automatically called to recompute the output + # 2. New caption is pushed back to the browser for re-display + # + # Note that because the data-oriented reactive expressions + # below don't depend on input$caption, those expressions are + # NOT called when input$caption changes + output$caption <- renderText({ + input$caption + }) + + # Generate a summary of the dataset ---- + # The output$summary depends on the datasetInput reactive + # expression, so will be re-executed whenever datasetInput is + # invalidated, i.e. whenever the input$dataset changes + output$summary <- renderPrint({ + dataset <- datasetInput() + summary(dataset) + }) + + # Show the first "n" observations ---- + # The output$view depends on both the databaseInput reactive + # expression and input$obs, so it will be re-executed whenever + # input$dataset or input$obs is changed + output$view <- renderTable({ + head(datasetInput(), n = input$obs) + }) + +} + +# Create Shiny app ---- +shinyApp(ui, server) diff --git a/inst/examples/04_mpg_legacy/DESCRIPTION b/inst/examples/04_mpg_legacy/DESCRIPTION new file mode 100644 index 0000000000..324145bbd7 --- /dev/null +++ b/inst/examples/04_mpg_legacy/DESCRIPTION @@ -0,0 +1,7 @@ +Title: Miles Per Gallon +Author: RStudio, Inc. +AuthorUrl: http://www.rstudio.com/ +License: MIT +DisplayMode: Showcase +Tags: getting-started +Type: Shiny diff --git a/inst/examples/04_mpg_legacy/Readme.md b/inst/examples/04_mpg_legacy/Readme.md new file mode 100644 index 0000000000..33c0fe096f --- /dev/null +++ b/inst/examples/04_mpg_legacy/Readme.md @@ -0,0 +1,4 @@ +This example demonstrates the following concepts: + +- **Global variables**: The `mpgData` variable is declared outside of the `ui` and `server` function definitions. This makes it available anywhere inside `app.R`. The code in `app.R` outside of `ui` and `server` function definitions is only run once when the app starts up, so it can't contain user input. +- **Reactive expressions**: `formulaText` is a reactive expression. Note how it re-evaluates when the Variable field is changed, but not when the Show Outliers box is unchecked. diff --git a/inst/examples/04_mpg_legacy/app.R b/inst/examples/04_mpg_legacy/app.R new file mode 100644 index 0000000000..e789bedcc9 --- /dev/null +++ b/inst/examples/04_mpg_legacy/app.R @@ -0,0 +1,75 @@ +library(shiny) +library(datasets) + +# Data pre-processing ---- +# Tweak the "am" variable to have nicer factor labels -- since this +# doesn't rely on any user inputs, we can do this once at startup +# and then use the value throughout the lifetime of the app +mpgData <- mtcars +mpgData$am <- factor(mpgData$am, labels = c("Automatic", "Manual")) + + +# Define UI for miles per gallon app ---- +ui <- fluidPage( + + # App title ---- + titlePanel("Miles Per Gallon"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- + sidebarPanel( + + # Input: Selector for variable to plot against mpg ---- + selectInput("variable", "Variable:", + c("Cylinders" = "cyl", + "Transmission" = "am", + "Gears" = "gear")), + + # Input: Checkbox for whether outliers should be included ---- + checkboxInput("outliers", "Show outliers", TRUE) + + ), + + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Formatted text for caption ---- + h3(textOutput("caption")), + + # Output: Plot of the requested variable against mpg ---- + plotOutput("mpgPlot") + + ) + ) +) + +# Define server logic to plot various variables against mpg ---- +server <- function(input, output) { + + # Compute the formula text ---- + # This is in a reactive expression since it is shared by the + # output$caption and output$mpgPlot functions + formulaText <- reactive({ + paste("mpg ~", input$variable) + }) + + # Return the formula text for printing as a caption ---- + output$caption <- renderText({ + formulaText() + }) + + # Generate a plot of the requested variable against mpg ---- + # and only exclude outliers if requested + output$mpgPlot <- renderPlot({ + boxplot(as.formula(formulaText()), + data = mpgData, + outline = input$outliers, + col = "#75AADB", pch = 19) + }) + +} + +# Create Shiny app ---- +shinyApp(ui, server) diff --git a/inst/examples/05_sliders_legacy/DESCRIPTION b/inst/examples/05_sliders_legacy/DESCRIPTION new file mode 100644 index 0000000000..954fddbf21 --- /dev/null +++ b/inst/examples/05_sliders_legacy/DESCRIPTION @@ -0,0 +1,7 @@ +Title: Sliders +Author: RStudio, Inc. +AuthorUrl: http://www.rstudio.com/ +License: MIT +DisplayMode: Showcase +Tags: getting-started +Type: Shiny diff --git a/inst/examples/05_sliders_legacy/Readme.md b/inst/examples/05_sliders_legacy/Readme.md new file mode 100644 index 0000000000..1b0cf572d0 --- /dev/null +++ b/inst/examples/05_sliders_legacy/Readme.md @@ -0,0 +1,3 @@ +This example demonstrates Shiny's versatile `sliderInput` widget. + +Slider inputs can be used to select single values, to select a continuous range of values, and even to animate over a range. diff --git a/inst/examples/05_sliders_legacy/app.R b/inst/examples/05_sliders_legacy/app.R new file mode 100644 index 0000000000..d9aa05c727 --- /dev/null +++ b/inst/examples/05_sliders_legacy/app.R @@ -0,0 +1,86 @@ +library(shiny) + +# Define UI for slider demo app ---- +ui <- fluidPage( + + # App title ---- + titlePanel("Sliders"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar to demonstrate various slider options ---- + sidebarPanel( + + # Input: Simple integer interval ---- + sliderInput("integer", "Integer:", + min = 0, max = 1000, + value = 500), + + # Input: Decimal interval with step value ---- + sliderInput("decimal", "Decimal:", + min = 0, max = 1, + value = 0.5, step = 0.1), + + # Input: Specification of range within an interval ---- + sliderInput("range", "Range:", + min = 1, max = 1000, + value = c(200,500)), + + # Input: Custom currency format for with basic animation ---- + sliderInput("format", "Custom Format:", + min = 0, max = 10000, + value = 0, step = 2500, + pre = "$", sep = ",", + animate = TRUE), + + # Input: Animation with custom interval (in ms) ---- + # to control speed, plus looping + sliderInput("animation", "Looping Animation:", + min = 1, max = 2000, + value = 1, step = 10, + animate = + animationOptions(interval = 300, loop = TRUE)) + + ), + + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Table summarizing the values entered ---- + tableOutput("values") + + ) + ) +) + +# Define server logic for slider examples ---- +server <- function(input, output) { + + # Reactive expression to create data frame of all input values ---- + sliderValues <- reactive({ + + data.frame( + Name = c("Integer", + "Decimal", + "Range", + "Custom Format", + "Animation"), + Value = as.character(c(input$integer, + input$decimal, + paste(input$range, collapse = " "), + input$format, + input$animation)), + stringsAsFactors = FALSE) + + }) + + # Show the values in an HTML table ---- + output$values <- renderTable({ + sliderValues() + }) + +} + +# Create Shiny app ---- +shinyApp(ui, server) diff --git a/inst/examples/06_tabsets_legacy/DESCRIPTION b/inst/examples/06_tabsets_legacy/DESCRIPTION new file mode 100644 index 0000000000..52c09c57ad --- /dev/null +++ b/inst/examples/06_tabsets_legacy/DESCRIPTION @@ -0,0 +1,7 @@ +Title: Tabsets +Author: RStudio, Inc. +AuthorUrl: http://www.rstudio.com/ +License: MIT +DisplayMode: Showcase +Tags: getting-started +Type: Shiny diff --git a/inst/examples/06_tabsets_legacy/Readme.md b/inst/examples/06_tabsets_legacy/Readme.md new file mode 100644 index 0000000000..c548d306d0 --- /dev/null +++ b/inst/examples/06_tabsets_legacy/Readme.md @@ -0,0 +1,9 @@ +This example demonstrates the `tabsetPanel` and `tabPanel` widgets. + +Notice that outputs that are not visible are not re-evaluated until they become visible. Try this: + +1. Scroll to the bottom of the `server` function. You might need to use the *show with app* option so you can easily view the code and interact with the app at the same time. +2. Change the number of observations, and observe that only `output$plot` is evaluated. +3. Click the Summary tab, and observe that `output$summary` is evaluated. +4. Change the number of observations again, and observe that now only `output$summary` is evaluated. + diff --git a/inst/examples/06_tabsets_legacy/app.R b/inst/examples/06_tabsets_legacy/app.R new file mode 100644 index 0000000000..e1b89d6644 --- /dev/null +++ b/inst/examples/06_tabsets_legacy/app.R @@ -0,0 +1,92 @@ +library(shiny) + +# Define UI for random distribution app ---- +ui <- fluidPage( + + # App title ---- + titlePanel("Tabsets"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- + sidebarPanel( + + # Input: Select the random distribution type ---- + radioButtons("dist", "Distribution type:", + c("Normal" = "norm", + "Uniform" = "unif", + "Log-normal" = "lnorm", + "Exponential" = "exp")), + + # br() element to introduce extra vertical spacing ---- + br(), + + # Input: Slider for the number of observations to generate ---- + sliderInput("n", + "Number of observations:", + value = 500, + min = 1, + max = 1000) + + ), + + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Tabset w/ plot, summary, and table ---- + tabsetPanel(type = "tabs", + tabPanel("Plot", plotOutput("plot")), + tabPanel("Summary", verbatimTextOutput("summary")), + tabPanel("Table", tableOutput("table")) + ) + + ) + ) +) + +# Define server logic for random distribution app ---- +server <- function(input, output) { + + # Reactive expression to generate the requested distribution ---- + # This is called whenever the inputs change. The output functions + # defined below then use the value computed from this expression + d <- reactive({ + dist <- switch(input$dist, + norm = rnorm, + unif = runif, + lnorm = rlnorm, + exp = rexp, + rnorm) + + dist(input$n) + }) + + # Generate a plot of the data ---- + # Also uses the inputs to build the plot label. Note that the + # dependencies on the inputs and the data reactive expression are + # both tracked, and all expressions are called in the sequence + # implied by the dependency graph. + output$plot <- renderPlot({ + dist <- input$dist + n <- input$n + + hist(d(), + main = paste("r", dist, "(", n, ")", sep = ""), + col = "#75AADB", border = "white") + }) + + # Generate a summary of the data ---- + output$summary <- renderPrint({ + summary(d()) + }) + + # Generate an HTML table view of the data ---- + output$table <- renderTable({ + d() + }) + +} + +# Create Shiny app ---- +shinyApp(ui, server) diff --git a/inst/examples/07_widgets_legacy/DESCRIPTION b/inst/examples/07_widgets_legacy/DESCRIPTION new file mode 100644 index 0000000000..b2ad51f7ce --- /dev/null +++ b/inst/examples/07_widgets_legacy/DESCRIPTION @@ -0,0 +1,7 @@ +Title: Widgets +Author: RStudio, Inc. +AuthorUrl: http://www.rstudio.com/ +License: MIT +DisplayMode: Showcase +Tags: getting-started +Type: Shiny diff --git a/inst/examples/07_widgets_legacy/Readme.md b/inst/examples/07_widgets_legacy/Readme.md new file mode 100644 index 0000000000..25a4ad02cd --- /dev/null +++ b/inst/examples/07_widgets_legacy/Readme.md @@ -0,0 +1 @@ +This example demonstrates some additional widgets included in Shiny, such as `helpText` and `actionButton`. The latter is used to delay rendering output until the user explicitly requests it (a construct which also introduces two important server functions, `eventReactive` and `isolate`). diff --git a/inst/examples/07_widgets_legacy/app.R b/inst/examples/07_widgets_legacy/app.R new file mode 100644 index 0000000000..4ad8e88e7e --- /dev/null +++ b/inst/examples/07_widgets_legacy/app.R @@ -0,0 +1,82 @@ +library(shiny) + +# Define UI for dataset viewer app ---- +ui <- fluidPage( + + # App title ---- + titlePanel("More Widgets"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- + sidebarPanel( + + # Input: Select a dataset ---- + selectInput("dataset", "Choose a dataset:", + choices = c("rock", "pressure", "cars")), + + # Input: Specify the number of observations to view ---- + numericInput("obs", "Number of observations to view:", 10), + + # Include clarifying text ---- + helpText("Note: while the data view will show only the specified", + "number of observations, the summary will still be based", + "on the full dataset."), + + # Input: actionButton() to defer the rendering of output ---- + # until the user explicitly clicks the button (rather than + # doing it immediately when inputs change). This is useful if + # the computations required to render output are inordinately + # time-consuming. + actionButton("update", "Update View") + + ), + + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Header + summary of distribution ---- + h4("Summary"), + verbatimTextOutput("summary"), + + # Output: Header + table of distribution ---- + h4("Observations"), + tableOutput("view") + ) + + ) +) + +# Define server logic to summarize and view selected dataset ---- +server <- function(input, output) { + + # Return the requested dataset ---- + # Note that we use eventReactive() here, which depends on + # input$update (the action button), so that the output is only + # updated when the user clicks the button + datasetInput <- eventReactive(input$update, { + switch(input$dataset, + "rock" = rock, + "pressure" = pressure, + "cars" = cars) + }, ignoreNULL = FALSE) + + # Generate a summary of the dataset ---- + output$summary <- renderPrint({ + dataset <- datasetInput() + summary(dataset) + }) + + # Show the first "n" observations ---- + # The use of isolate() is necessary because we don't want the table + # to update whenever input$obs changes (only when the user clicks + # the action button) + output$view <- renderTable({ + head(datasetInput(), n = isolate(input$obs)) + }) + +} + +# Create Shiny app ---- +shinyApp(ui, server) diff --git a/inst/examples/08_html_legacy/DESCRIPTION b/inst/examples/08_html_legacy/DESCRIPTION new file mode 100644 index 0000000000..76a9c2187c --- /dev/null +++ b/inst/examples/08_html_legacy/DESCRIPTION @@ -0,0 +1,7 @@ +Title: Custom HTML UI +Author: RStudio, Inc. +AuthorUrl: http://www.rstudio.com/ +License: MIT +DisplayMode: Showcase +Tags: getting-started +Type: Shiny diff --git a/inst/examples/08_html_legacy/Readme.md b/inst/examples/08_html_legacy/Readme.md new file mode 100644 index 0000000000..c2c898dcd3 --- /dev/null +++ b/inst/examples/08_html_legacy/Readme.md @@ -0,0 +1 @@ +Normally we use the built-in functions, such as `textInput()`, to generate the HTML UI in the R script `ui.R`. Actually **shiny** also works with a custom HTML page `www/index.html`. See [the tutorial](http://shiny.rstudio.com/tutorial/) for more details. diff --git a/inst/examples/08_html_legacy/app.R b/inst/examples/08_html_legacy/app.R new file mode 100644 index 0000000000..be8d378415 --- /dev/null +++ b/inst/examples/08_html_legacy/app.R @@ -0,0 +1,47 @@ +library(shiny) + +# Define server logic for random distribution app ---- +server <- function(input, output) { + + # Reactive expression to generate the requested distribution ---- + # This is called whenever the inputs change. The output functions + # defined below then use the value computed from this expression + d <- reactive({ + dist <- switch(input$dist, + norm = rnorm, + unif = runif, + lnorm = rlnorm, + exp = rexp, + rnorm) + + dist(input$n) + }) + + # Generate a plot of the data ---- + # Also uses the inputs to build the plot label. Note that the + # dependencies on the inputs and the data reactive expression are + # both tracked, and all expressions are called in the sequence + # implied by the dependency graph. + output$plot <- renderPlot({ + dist <- input$dist + n <- input$n + + hist(d(), + main = paste("r", dist, "(", n, ")", sep = ""), + col = "#75AADB", border = "white") + }) + + # Generate a summary of the data ---- + output$summary <- renderPrint({ + summary(d()) + }) + + # Generate an HTML table view of the head of the data ---- + output$table <- renderTable({ + head(data.frame(x = d())) + }) + +} + +# Create Shiny app ---- +shinyApp(ui = htmlTemplate("www/index.html"), server) diff --git a/inst/examples/08_html_legacy/www/index.html b/inst/examples/08_html_legacy/www/index.html new file mode 100644 index 0000000000..b32adc30b6 --- /dev/null +++ b/inst/examples/08_html_legacy/www/index.html @@ -0,0 +1,41 @@ + + + + + + + + + + +

HTML UI

+ +

+
+ +

+ +

+ +
+ + +

+ +

Summary of data:

+

+
+  

Plot of data:

+
+ +

Head of data:

+
+ + + diff --git a/inst/examples/09_upload_legacy/DESCRIPTION b/inst/examples/09_upload_legacy/DESCRIPTION new file mode 100644 index 0000000000..b5e24c3a13 --- /dev/null +++ b/inst/examples/09_upload_legacy/DESCRIPTION @@ -0,0 +1,7 @@ +Title: File Upload +Author: RStudio, Inc. +AuthorUrl: http://www.rstudio.com/ +License: MIT +DisplayMode: Showcase +Tags: getting-started +Type: Shiny diff --git a/inst/examples/09_upload_legacy/Readme.md b/inst/examples/09_upload_legacy/Readme.md new file mode 100644 index 0000000000..3c45f363d5 --- /dev/null +++ b/inst/examples/09_upload_legacy/Readme.md @@ -0,0 +1,3 @@ +We can add a file upload input in the UI using the function `fileInput()`, +e.g. `fileInput('foo')`. In the `server` function, we can access the +uploaded files via `input$foo`. diff --git a/inst/examples/09_upload_legacy/app.R b/inst/examples/09_upload_legacy/app.R new file mode 100644 index 0000000000..64d5ead234 --- /dev/null +++ b/inst/examples/09_upload_legacy/app.R @@ -0,0 +1,92 @@ +library(shiny) + +# Define UI for data upload app ---- +ui <- fluidPage( + + # App title ---- + titlePanel("Uploading Files"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- + sidebarPanel( + + # Input: Select a file ---- + fileInput("file1", "Choose CSV File", + multiple = TRUE, + accept = c("text/csv", + "text/comma-separated-values,text/plain", + ".csv")), + + # Horizontal line ---- + tags$hr(), + + # Input: Checkbox if file has header ---- + checkboxInput("header", "Header", TRUE), + + # Input: Select separator ---- + radioButtons("sep", "Separator", + choices = c(Comma = ",", + Semicolon = ";", + Tab = "\t"), + selected = ","), + + # Input: Select quotes ---- + radioButtons("quote", "Quote", + choices = c(None = "", + "Double Quote" = '"', + "Single Quote" = "'"), + selected = '"'), + + # Horizontal line ---- + tags$hr(), + + # Input: Select number of rows to display ---- + radioButtons("disp", "Display", + choices = c(Head = "head", + All = "all"), + selected = "head") + + ), + + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Data file ---- + tableOutput("contents") + + ) + + ) +) + +# Define server logic to read selected file ---- +server <- function(input, output) { + + output$contents <- renderTable({ + + # input$file1 will be NULL initially. After the user selects + # and uploads a file, head of that data file by default, + # or all rows if selected, will be shown. + + req(input$file1) + + df <- read.csv(input$file1$datapath, + header = input$header, + sep = input$sep, + quote = input$quote) + + if(input$disp == "head") { + return(head(df)) + } + else { + return(df) + } + + }) + +} + +# Create Shiny app ---- +shinyApp(ui, server) diff --git a/inst/examples/10_download_legacy/DESCRIPTION b/inst/examples/10_download_legacy/DESCRIPTION new file mode 100644 index 0000000000..3eb34a7f8e --- /dev/null +++ b/inst/examples/10_download_legacy/DESCRIPTION @@ -0,0 +1,7 @@ +Title: File Download +Author: RStudio, Inc. +AuthorUrl: http://www.rstudio.com/ +License: MIT +DisplayMode: Showcase +Tags: getting-started +Type: Shiny diff --git a/inst/examples/10_download_legacy/Readme.md b/inst/examples/10_download_legacy/Readme.md new file mode 100644 index 0000000000..fceb331ab7 --- /dev/null +++ b/inst/examples/10_download_legacy/Readme.md @@ -0,0 +1,2 @@ +We can add a download button to the UI using `downloadButton()`, and write +the content of the file in `downloadHandler()` in the `server` function. diff --git a/inst/examples/10_download_legacy/app.R b/inst/examples/10_download_legacy/app.R new file mode 100644 index 0000000000..b5a6dd1f22 --- /dev/null +++ b/inst/examples/10_download_legacy/app.R @@ -0,0 +1,63 @@ +library(shiny) + +# Define UI for data download app ---- +ui <- fluidPage( + + # App title ---- + titlePanel("Downloading Data"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- + sidebarPanel( + + # Input: Choose dataset ---- + selectInput("dataset", "Choose a dataset:", + choices = c("rock", "pressure", "cars")), + + # Button + downloadButton("downloadData", "Download") + + ), + + # Main panel for displaying outputs ---- + mainPanel( + + tableOutput("table") + + ) + + ) +) + +# Define server logic to display and download selected file ---- +server <- function(input, output) { + + # Reactive value for selected dataset ---- + datasetInput <- reactive({ + switch(input$dataset, + "rock" = rock, + "pressure" = pressure, + "cars" = cars) + }) + + # Table of selected dataset ---- + output$table <- renderTable({ + datasetInput() + }) + + # Downloadable csv of selected dataset ---- + output$downloadData <- downloadHandler( + filename = function() { + paste(input$dataset, ".csv", sep = "") + }, + content = function(file) { + write.csv(datasetInput(), file, row.names = FALSE) + } + ) + +} + +# Create Shiny app ---- +shinyApp(ui, server) diff --git a/inst/examples/11_timer_legacy/DESCRIPTION b/inst/examples/11_timer_legacy/DESCRIPTION new file mode 100644 index 0000000000..3412d2f96c --- /dev/null +++ b/inst/examples/11_timer_legacy/DESCRIPTION @@ -0,0 +1,7 @@ +Title: Timer +Author: RStudio, Inc. +AuthorUrl: http://www.rstudio.com/ +License: MIT +DisplayMode: Showcase +Tags: getting-started +Type: Shiny diff --git a/inst/examples/11_timer_legacy/Readme.md b/inst/examples/11_timer_legacy/Readme.md new file mode 100644 index 0000000000..b9a617389a --- /dev/null +++ b/inst/examples/11_timer_legacy/Readme.md @@ -0,0 +1,4 @@ +The function `invalidateLater()` can be used to invalidate an observer or +reactive expression in a given number of milliseconds. In this example, the +output `currentTime` is updated every second, so it shows the current time +on a second basis. diff --git a/inst/examples/11_timer_legacy/app.R b/inst/examples/11_timer_legacy/app.R new file mode 100644 index 0000000000..6aaf3792d9 --- /dev/null +++ b/inst/examples/11_timer_legacy/app.R @@ -0,0 +1,21 @@ +library(shiny) + +# Define UI for displaying current time ---- +ui <- fluidPage( + + h2(textOutput("currentTime")) + +) + +# Define server logic to show current time, update every second ---- +server <- function(input, output, session) { + + output$currentTime <- renderText({ + invalidateLater(1000, session) + paste("The current time is", Sys.time()) + }) + +} + +# Create Shiny app ---- +shinyApp(ui, server) From 45f61758c62b0e0d873d5863b32e43cd0520e8e7 Mon Sep 17 00:00:00 2001 From: Garrett Grolemund Date: Thu, 4 Jan 2024 15:00:17 -0600 Subject: [PATCH 04/18] Switches tabset example to use navset_card_underline() --- inst/examples/06_tabsets/app.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/examples/06_tabsets/app.R b/inst/examples/06_tabsets/app.R index 6059bc35f2..33e485d8ae 100644 --- a/inst/examples/06_tabsets/app.R +++ b/inst/examples/06_tabsets/app.R @@ -29,7 +29,7 @@ ui <- page_sidebar( # Main panel for displaying outputs ---- # Output: A tabset that combines three panels ---- - navset_underline( + navset_card_underline( # Panel with plot ---- nav_panel("Plot", plotOutput("plot")), From 4a1c8de5f0e2a69e57524032f19798b93d01bb06 Mon Sep 17 00:00:00 2001 From: Garrett Grolemund Date: Fri, 12 Jan 2024 10:49:09 -0600 Subject: [PATCH 05/18] Updates example 2 --- inst/examples/02_text/app.R | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/inst/examples/02_text/app.R b/inst/examples/02_text/app.R index 9aff1e850c..839dbe50bf 100644 --- a/inst/examples/02_text/app.R +++ b/inst/examples/02_text/app.R @@ -1,17 +1,15 @@ library(shiny) +library(bslib) # Define UI for dataset viewer app ---- -ui <- fluidPage( +ui <- page_sidebar( # App title ---- - titlePanel("Shiny Text"), - - # Sidebar layout with a input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- - sidebarPanel( + title = "Shiny Text", + # Sidebar panel for inputs ---- + sidebar = + sidebar( # Input: Selector for choosing dataset ---- selectInput(inputId = "dataset", label = "Choose a dataset:", @@ -22,18 +20,11 @@ ui <- fluidPage( label = "Number of observations to view:", value = 10) ), + # Output: Verbatim text for data summary ---- + verbatimTextOutput("summary"), - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Verbatim text for data summary ---- - verbatimTextOutput("summary"), - - # Output: HTML table with requested number of observations ---- - tableOutput("view") - - ) - ) + # Output: HTML table with requested number of observations ---- + tableOutput("view") ) # Define server logic to summarize and view selected dataset ---- From d02fa9384a9dc7308eaa9b59d9f565f095f7e1d3 Mon Sep 17 00:00:00 2001 From: Garrett Grolemund Date: Fri, 12 Jan 2024 10:51:27 -0600 Subject: [PATCH 06/18] Updates 03_reactivity --- inst/examples/03_reactivity/app.R | 32 ++++++++++++------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/inst/examples/03_reactivity/app.R b/inst/examples/03_reactivity/app.R index 393ebfe619..7f08cfd221 100644 --- a/inst/examples/03_reactivity/app.R +++ b/inst/examples/03_reactivity/app.R @@ -1,16 +1,14 @@ library(shiny) +library(bslib) # Define UI for dataset viewer app ---- -ui <- fluidPage( +ui <- page_sidebar( # App title ---- - titlePanel("Reactivity"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- - sidebarPanel( + title = "Reactivity", + # Sidebar panel for inputs ---- + sidebar = + sidebar( # Input: Text for providing a caption ---- # Note: Changes made to the caption in the textInput control @@ -31,20 +29,14 @@ ui <- fluidPage( ), - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Formatted text for caption ---- - h3(textOutput("caption", container = span)), - - # Output: Verbatim text for data summary ---- - verbatimTextOutput("summary"), + # Output: Formatted text for caption ---- + h3(textOutput("caption", container = span)), - # Output: HTML table with requested number of observations ---- - tableOutput("view") + # Output: Verbatim text for data summary ---- + verbatimTextOutput("summary"), - ) - ) + # Output: HTML table with requested number of observations ---- + tableOutput("view") ) # Define server logic to summarize and view selected dataset ---- From 6925463ba7e0e147822e3b9339db3610dd6f652f Mon Sep 17 00:00:00 2001 From: Garrett Grolemund Date: Fri, 12 Jan 2024 10:52:57 -0600 Subject: [PATCH 07/18] Updates 04_mpg --- inst/examples/04_mpg/app.R | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/inst/examples/04_mpg/app.R b/inst/examples/04_mpg/app.R index e789bedcc9..6357c02ca3 100644 --- a/inst/examples/04_mpg/app.R +++ b/inst/examples/04_mpg/app.R @@ -1,4 +1,5 @@ library(shiny) +library(bslib) library(datasets) # Data pre-processing ---- @@ -10,15 +11,12 @@ mpgData$am <- factor(mpgData$am, labels = c("Automatic", "Manual")) # Define UI for miles per gallon app ---- -ui <- fluidPage( +ui <- page_sidebar( # App title ---- - titlePanel("Miles Per Gallon"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- + title = "Miles Per Gallon", + # Sidebar panel for inputs ---- + sidebar = sidebarPanel( # Input: Selector for variable to plot against mpg ---- @@ -32,17 +30,11 @@ ui <- fluidPage( ), - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Formatted text for caption ---- - h3(textOutput("caption")), - - # Output: Plot of the requested variable against mpg ---- - plotOutput("mpgPlot") + # Output: Formatted text for caption ---- + h3(textOutput("caption")), - ) - ) + # Output: Plot of the requested variable against mpg ---- + plotOutput("mpgPlot") ) # Define server logic to plot various variables against mpg ---- From 06371af8ccefa62a6fd7727aa9032fb5134e08f0 Mon Sep 17 00:00:00 2001 From: Garrett Grolemund Date: Fri, 12 Jan 2024 10:54:52 -0600 Subject: [PATCH 08/18] Updates 05_sliders --- inst/examples/05_sliders/app.R | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/inst/examples/05_sliders/app.R b/inst/examples/05_sliders/app.R index d9aa05c727..eb6e86181e 100644 --- a/inst/examples/05_sliders/app.R +++ b/inst/examples/05_sliders/app.R @@ -1,16 +1,14 @@ library(shiny) +library(bslib) # Define UI for slider demo app ---- -ui <- fluidPage( +ui <- page_sidebar( # App title ---- - titlePanel("Sliders"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar to demonstrate various slider options ---- - sidebarPanel( + title = "Sliders", + # Sidebar panel for inputs ---- + sidebar = + sidebar( # Input: Simple integer interval ---- sliderInput("integer", "Integer:", @@ -44,14 +42,8 @@ ui <- fluidPage( ), - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Table summarizing the values entered ---- - tableOutput("values") - - ) - ) + # Output: Table summarizing the values entered ---- + tableOutput("values") ) # Define server logic for slider examples ---- From 69540c10265013ae0088f3c0ff745e556add9a68 Mon Sep 17 00:00:00 2001 From: Garrett Grolemund Date: Fri, 12 Jan 2024 10:56:00 -0600 Subject: [PATCH 09/18] Updates 07_widgets --- inst/examples/07_widgets/app.R | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/inst/examples/07_widgets/app.R b/inst/examples/07_widgets/app.R index 4ad8e88e7e..acf92a0d71 100644 --- a/inst/examples/07_widgets/app.R +++ b/inst/examples/07_widgets/app.R @@ -1,16 +1,14 @@ library(shiny) +library(bslib) -# Define UI for dataset viewer app ---- -ui <- fluidPage( +# Define UI for slider demo app ---- +ui <- page_sidebar( # App title ---- - titlePanel("More Widgets"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- - sidebarPanel( + title = "More Widgets", + # Sidebar panel for inputs ---- + sidebar = + sidebar( # Input: Select a dataset ---- selectInput("dataset", "Choose a dataset:", @@ -33,19 +31,13 @@ ui <- fluidPage( ), - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Header + summary of distribution ---- - h4("Summary"), - verbatimTextOutput("summary"), - - # Output: Header + table of distribution ---- - h4("Observations"), - tableOutput("view") - ) + # Output: Header + summary of distribution ---- + h4("Summary"), + verbatimTextOutput("summary"), - ) + # Output: Header + table of distribution ---- + h4("Observations"), + tableOutput("view") ) # Define server logic to summarize and view selected dataset ---- From 3e8a12b8a464a01a15bc3700c168dd0161f6004c Mon Sep 17 00:00:00 2001 From: Garrett Grolemund Date: Fri, 12 Jan 2024 10:57:46 -0600 Subject: [PATCH 10/18] Deletes 08_html_legacy. Original example does not need updated. --- inst/examples/08_html_legacy/DESCRIPTION | 7 --- inst/examples/08_html_legacy/Readme.md | 1 - inst/examples/08_html_legacy/app.R | 47 --------------------- inst/examples/08_html_legacy/www/index.html | 41 ------------------ 4 files changed, 96 deletions(-) delete mode 100644 inst/examples/08_html_legacy/DESCRIPTION delete mode 100644 inst/examples/08_html_legacy/Readme.md delete mode 100644 inst/examples/08_html_legacy/app.R delete mode 100644 inst/examples/08_html_legacy/www/index.html diff --git a/inst/examples/08_html_legacy/DESCRIPTION b/inst/examples/08_html_legacy/DESCRIPTION deleted file mode 100644 index 76a9c2187c..0000000000 --- a/inst/examples/08_html_legacy/DESCRIPTION +++ /dev/null @@ -1,7 +0,0 @@ -Title: Custom HTML UI -Author: RStudio, Inc. -AuthorUrl: http://www.rstudio.com/ -License: MIT -DisplayMode: Showcase -Tags: getting-started -Type: Shiny diff --git a/inst/examples/08_html_legacy/Readme.md b/inst/examples/08_html_legacy/Readme.md deleted file mode 100644 index c2c898dcd3..0000000000 --- a/inst/examples/08_html_legacy/Readme.md +++ /dev/null @@ -1 +0,0 @@ -Normally we use the built-in functions, such as `textInput()`, to generate the HTML UI in the R script `ui.R`. Actually **shiny** also works with a custom HTML page `www/index.html`. See [the tutorial](http://shiny.rstudio.com/tutorial/) for more details. diff --git a/inst/examples/08_html_legacy/app.R b/inst/examples/08_html_legacy/app.R deleted file mode 100644 index be8d378415..0000000000 --- a/inst/examples/08_html_legacy/app.R +++ /dev/null @@ -1,47 +0,0 @@ -library(shiny) - -# Define server logic for random distribution app ---- -server <- function(input, output) { - - # Reactive expression to generate the requested distribution ---- - # This is called whenever the inputs change. The output functions - # defined below then use the value computed from this expression - d <- reactive({ - dist <- switch(input$dist, - norm = rnorm, - unif = runif, - lnorm = rlnorm, - exp = rexp, - rnorm) - - dist(input$n) - }) - - # Generate a plot of the data ---- - # Also uses the inputs to build the plot label. Note that the - # dependencies on the inputs and the data reactive expression are - # both tracked, and all expressions are called in the sequence - # implied by the dependency graph. - output$plot <- renderPlot({ - dist <- input$dist - n <- input$n - - hist(d(), - main = paste("r", dist, "(", n, ")", sep = ""), - col = "#75AADB", border = "white") - }) - - # Generate a summary of the data ---- - output$summary <- renderPrint({ - summary(d()) - }) - - # Generate an HTML table view of the head of the data ---- - output$table <- renderTable({ - head(data.frame(x = d())) - }) - -} - -# Create Shiny app ---- -shinyApp(ui = htmlTemplate("www/index.html"), server) diff --git a/inst/examples/08_html_legacy/www/index.html b/inst/examples/08_html_legacy/www/index.html deleted file mode 100644 index b32adc30b6..0000000000 --- a/inst/examples/08_html_legacy/www/index.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - -

HTML UI

- -

-
- -

- -

- -
- - -

- -

Summary of data:

-

-
-  

Plot of data:

-
- -

Head of data:

-
- - - From 987be9b234f797a3bc028ea3f0432e0a949fa2cb Mon Sep 17 00:00:00 2001 From: Garrett Grolemund Date: Fri, 12 Jan 2024 10:58:53 -0600 Subject: [PATCH 11/18] Updates 09_upload --- inst/examples/09_upload/app.R | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/inst/examples/09_upload/app.R b/inst/examples/09_upload/app.R index 64d5ead234..50ec449a85 100644 --- a/inst/examples/09_upload/app.R +++ b/inst/examples/09_upload/app.R @@ -1,16 +1,14 @@ library(shiny) +library(bslib) -# Define UI for data upload app ---- -ui <- fluidPage( +# Define UI for slider demo app ---- +ui <- page_sidebar( # App title ---- - titlePanel("Uploading Files"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- - sidebarPanel( + title = "Uploading Files", + # Sidebar panel for inputs ---- + sidebar = + sidebar( # Input: Select a file ---- fileInput("file1", "Choose CSV File", @@ -50,15 +48,8 @@ ui <- fluidPage( ), - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Data file ---- - tableOutput("contents") - - ) - - ) + # Output: Data file ---- + tableOutput("contents") ) # Define server logic to read selected file ---- From 066dca9c7d2616f5ca61c7965078c10fd336b905 Mon Sep 17 00:00:00 2001 From: Garrett Grolemund Date: Fri, 12 Jan 2024 11:03:07 -0600 Subject: [PATCH 12/18] Updates 10_download --- inst/examples/10_download/app.R | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/inst/examples/10_download/app.R b/inst/examples/10_download/app.R index b5a6dd1f22..8a778b77a8 100644 --- a/inst/examples/10_download/app.R +++ b/inst/examples/10_download/app.R @@ -1,16 +1,14 @@ library(shiny) +library(bslib) -# Define UI for data download app ---- -ui <- fluidPage( +# Define UI for slider demo app ---- +ui <- page_sidebar( # App title ---- - titlePanel("Downloading Data"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- - sidebarPanel( + title = "Downloading Data", + # Sidebar panel for inputs ---- + sidebar = + sidebar( # Input: Choose dataset ---- selectInput("dataset", "Choose a dataset:", @@ -21,14 +19,7 @@ ui <- fluidPage( ), - # Main panel for displaying outputs ---- - mainPanel( - - tableOutput("table") - - ) - - ) + tableOutput("table") ) # Define server logic to display and download selected file ---- From 950efb31e11c0b058ccc45882d807bfd68329e78 Mon Sep 17 00:00:00 2001 From: Garrett Grolemund Date: Fri, 12 Jan 2024 11:04:21 -0600 Subject: [PATCH 13/18] Updates 11_timer --- inst/examples/11_timer/app.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inst/examples/11_timer/app.R b/inst/examples/11_timer/app.R index 6aaf3792d9..f30a27996e 100644 --- a/inst/examples/11_timer/app.R +++ b/inst/examples/11_timer/app.R @@ -1,7 +1,8 @@ library(shiny) +library(bslib) # Define UI for displaying current time ---- -ui <- fluidPage( +ui <- page_fillable( h2(textOutput("currentTime")) From 0070fd00f97b04a1669afb0c9822360cb0cb4676 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 2 Feb 2024 16:22:40 -0600 Subject: [PATCH 14/18] Keep inst/example unchanged; add new examples under inst/shiny and update runExamples() to use that directory by default --- R/runapp.R | 4 +- inst/examples/01_hello/app.R | 27 +++++-- inst/examples/02_text/app.R | 29 ++++--- inst/examples/03_reactivity/app.R | 32 +++++--- inst/examples/04_mpg/app.R | 26 ++++--- inst/examples/05_sliders/app.R | 24 ++++-- inst/examples/06_tabsets/Readme.md | 2 +- inst/examples/06_tabsets/app.R | 75 ++++++++++--------- inst/examples/07_widgets/app.R | 34 +++++---- inst/examples/09_upload/app.R | 27 ++++--- inst/examples/10_download/app.R | 25 +++++-- inst/examples/11_timer/app.R | 3 +- .../01_hello}/DESCRIPTION | 0 .../01_hello}/Readme.md | 0 .../01_hello_legacy => shiny/01_hello}/app.R | 27 ++----- .../02_text}/DESCRIPTION | 0 .../02_text}/Readme.md | 0 .../02_text_legacy => shiny/02_text}/app.R | 29 +++---- .../03_reactivity}/DESCRIPTION | 0 .../03_reactivity}/Readme.md | 0 .../03_reactivity}/app.R | 32 +++----- .../04_mpg}/DESCRIPTION | 0 .../04_mpg_legacy => shiny/04_mpg}/Readme.md | 0 .../04_mpg_legacy => shiny/04_mpg}/app.R | 26 +++---- .../05_sliders}/DESCRIPTION | 0 .../05_sliders}/Readme.md | 0 .../05_sliders}/app.R | 24 ++---- .../06_tabsets}/DESCRIPTION | 0 .../06_tabsets}/Readme.md | 2 +- .../06_tabsets}/app.R | 75 +++++++++---------- .../07_widgets}/DESCRIPTION | 0 .../07_widgets}/Readme.md | 0 .../07_widgets}/app.R | 34 ++++----- inst/{examples => shiny}/08_html/DESCRIPTION | 0 inst/{examples => shiny}/08_html/Readme.md | 0 inst/{examples => shiny}/08_html/app.R | 0 .../08_html/www/index.html | 0 .../09_upload}/DESCRIPTION | 0 .../09_upload}/Readme.md | 0 .../09_upload}/app.R | 27 +++---- .../10_download}/DESCRIPTION | 0 .../10_download}/Readme.md | 0 .../10_download}/app.R | 25 ++----- .../11_timer}/DESCRIPTION | 0 .../11_timer}/Readme.md | 0 .../11_timer_legacy => shiny/11_timer}/app.R | 3 +- 46 files changed, 307 insertions(+), 305 deletions(-) rename inst/{examples/01_hello_legacy => shiny/01_hello}/DESCRIPTION (100%) rename inst/{examples/01_hello_legacy => shiny/01_hello}/Readme.md (100%) rename inst/{examples/01_hello_legacy => shiny/01_hello}/app.R (77%) rename inst/{examples/02_text_legacy => shiny/02_text}/DESCRIPTION (100%) rename inst/{examples/02_text_legacy => shiny/02_text}/Readme.md (100%) rename inst/{examples/02_text_legacy => shiny/02_text}/app.R (71%) rename inst/{examples/03_reactivity_legacy => shiny/03_reactivity}/DESCRIPTION (100%) rename inst/{examples/03_reactivity_legacy => shiny/03_reactivity}/Readme.md (100%) rename inst/{examples/03_reactivity_legacy => shiny/03_reactivity}/app.R (82%) rename inst/{examples/04_mpg_legacy => shiny/04_mpg}/DESCRIPTION (100%) rename inst/{examples/04_mpg_legacy => shiny/04_mpg}/Readme.md (100%) rename inst/{examples/04_mpg_legacy => shiny/04_mpg}/app.R (79%) rename inst/{examples/05_sliders_legacy => shiny/05_sliders}/DESCRIPTION (100%) rename inst/{examples/05_sliders_legacy => shiny/05_sliders}/Readme.md (100%) rename inst/{examples/05_sliders_legacy => shiny/05_sliders}/app.R (84%) rename inst/{examples/06_tabsets_legacy => shiny/06_tabsets}/DESCRIPTION (100%) rename inst/{examples/06_tabsets_legacy => shiny/06_tabsets}/Readme.md (85%) rename inst/{examples/06_tabsets_legacy => shiny/06_tabsets}/app.R (54%) rename inst/{examples/07_widgets_legacy => shiny/07_widgets}/DESCRIPTION (100%) rename inst/{examples/07_widgets_legacy => shiny/07_widgets}/Readme.md (100%) rename inst/{examples/07_widgets_legacy => shiny/07_widgets}/app.R (78%) rename inst/{examples => shiny}/08_html/DESCRIPTION (100%) rename inst/{examples => shiny}/08_html/Readme.md (100%) rename inst/{examples => shiny}/08_html/app.R (100%) rename inst/{examples => shiny}/08_html/www/index.html (100%) rename inst/{examples/09_upload_legacy => shiny/09_upload}/DESCRIPTION (100%) rename inst/{examples/09_upload_legacy => shiny/09_upload}/Readme.md (100%) rename inst/{examples/09_upload_legacy => shiny/09_upload}/app.R (83%) rename inst/{examples/10_download_legacy => shiny/10_download}/DESCRIPTION (100%) rename inst/{examples/10_download_legacy => shiny/10_download}/Readme.md (100%) rename inst/{examples/10_download_legacy => shiny/10_download}/app.R (74%) rename inst/{examples/11_timer_legacy => shiny/11_timer}/DESCRIPTION (100%) rename inst/{examples/11_timer_legacy => shiny/11_timer}/Readme.md (100%) rename inst/{examples/11_timer_legacy => shiny/11_timer}/app.R (91%) diff --git a/R/runapp.R b/R/runapp.R index f6cc86ff00..af3103d053 100644 --- a/R/runapp.R +++ b/R/runapp.R @@ -467,7 +467,9 @@ runExample <- function(example=NA, launch.browser = getOption('shiny.launch.browser', interactive()), host=getOption('shiny.host', '127.0.0.1'), display.mode=c("auto", "normal", "showcase")) { - examplesDir <- system_file('examples', package='shiny') + legacy <- getOption('shiny.legacy.examples', FALSE) + examplesDir <- if (isTRUE(legacy)) 'examples' else 'shiny' + examplesDir <- system_file(examplesDir, package='shiny') dir <- resolve(examplesDir, example) if (is.null(dir)) { if (is.na(example)) { diff --git a/inst/examples/01_hello/app.R b/inst/examples/01_hello/app.R index a098a7b422..887c50576d 100644 --- a/inst/examples/01_hello/app.R +++ b/inst/examples/01_hello/app.R @@ -1,23 +1,34 @@ library(shiny) -library(bslib) # Define UI for app that draws a histogram ---- -ui <- page_sidebar( +ui <- fluidPage( # App title ---- - title = "Hello Shiny!", - # Sidebar panel for inputs ---- - sidebar = - sidebar( + titlePanel("Hello Shiny!"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- + sidebarPanel( + # Input: Slider for the number of bins ---- sliderInput(inputId = "bins", label = "Number of bins:", min = 1, max = 50, value = 30) + ), - # Output: Histogram ---- - plotOutput(outputId = "distPlot") + + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Histogram ---- + plotOutput(outputId = "distPlot") + + ) + ) ) # Define server logic required to draw a histogram ---- diff --git a/inst/examples/02_text/app.R b/inst/examples/02_text/app.R index 839dbe50bf..9aff1e850c 100644 --- a/inst/examples/02_text/app.R +++ b/inst/examples/02_text/app.R @@ -1,15 +1,17 @@ library(shiny) -library(bslib) # Define UI for dataset viewer app ---- -ui <- page_sidebar( +ui <- fluidPage( # App title ---- - title = "Shiny Text", + titlePanel("Shiny Text"), + + # Sidebar layout with a input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- + sidebarPanel( - # Sidebar panel for inputs ---- - sidebar = - sidebar( # Input: Selector for choosing dataset ---- selectInput(inputId = "dataset", label = "Choose a dataset:", @@ -20,11 +22,18 @@ ui <- page_sidebar( label = "Number of observations to view:", value = 10) ), - # Output: Verbatim text for data summary ---- - verbatimTextOutput("summary"), - # Output: HTML table with requested number of observations ---- - tableOutput("view") + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Verbatim text for data summary ---- + verbatimTextOutput("summary"), + + # Output: HTML table with requested number of observations ---- + tableOutput("view") + + ) + ) ) # Define server logic to summarize and view selected dataset ---- diff --git a/inst/examples/03_reactivity/app.R b/inst/examples/03_reactivity/app.R index 7f08cfd221..393ebfe619 100644 --- a/inst/examples/03_reactivity/app.R +++ b/inst/examples/03_reactivity/app.R @@ -1,14 +1,16 @@ library(shiny) -library(bslib) # Define UI for dataset viewer app ---- -ui <- page_sidebar( +ui <- fluidPage( # App title ---- - title = "Reactivity", - # Sidebar panel for inputs ---- - sidebar = - sidebar( + titlePanel("Reactivity"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- + sidebarPanel( # Input: Text for providing a caption ---- # Note: Changes made to the caption in the textInput control @@ -29,14 +31,20 @@ ui <- page_sidebar( ), - # Output: Formatted text for caption ---- - h3(textOutput("caption", container = span)), + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Formatted text for caption ---- + h3(textOutput("caption", container = span)), + + # Output: Verbatim text for data summary ---- + verbatimTextOutput("summary"), - # Output: Verbatim text for data summary ---- - verbatimTextOutput("summary"), + # Output: HTML table with requested number of observations ---- + tableOutput("view") - # Output: HTML table with requested number of observations ---- - tableOutput("view") + ) + ) ) # Define server logic to summarize and view selected dataset ---- diff --git a/inst/examples/04_mpg/app.R b/inst/examples/04_mpg/app.R index 6357c02ca3..e789bedcc9 100644 --- a/inst/examples/04_mpg/app.R +++ b/inst/examples/04_mpg/app.R @@ -1,5 +1,4 @@ library(shiny) -library(bslib) library(datasets) # Data pre-processing ---- @@ -11,12 +10,15 @@ mpgData$am <- factor(mpgData$am, labels = c("Automatic", "Manual")) # Define UI for miles per gallon app ---- -ui <- page_sidebar( +ui <- fluidPage( # App title ---- - title = "Miles Per Gallon", - # Sidebar panel for inputs ---- - sidebar = + titlePanel("Miles Per Gallon"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- sidebarPanel( # Input: Selector for variable to plot against mpg ---- @@ -30,11 +32,17 @@ ui <- page_sidebar( ), - # Output: Formatted text for caption ---- - h3(textOutput("caption")), + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Formatted text for caption ---- + h3(textOutput("caption")), + + # Output: Plot of the requested variable against mpg ---- + plotOutput("mpgPlot") - # Output: Plot of the requested variable against mpg ---- - plotOutput("mpgPlot") + ) + ) ) # Define server logic to plot various variables against mpg ---- diff --git a/inst/examples/05_sliders/app.R b/inst/examples/05_sliders/app.R index eb6e86181e..d9aa05c727 100644 --- a/inst/examples/05_sliders/app.R +++ b/inst/examples/05_sliders/app.R @@ -1,14 +1,16 @@ library(shiny) -library(bslib) # Define UI for slider demo app ---- -ui <- page_sidebar( +ui <- fluidPage( # App title ---- - title = "Sliders", - # Sidebar panel for inputs ---- - sidebar = - sidebar( + titlePanel("Sliders"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar to demonstrate various slider options ---- + sidebarPanel( # Input: Simple integer interval ---- sliderInput("integer", "Integer:", @@ -42,8 +44,14 @@ ui <- page_sidebar( ), - # Output: Table summarizing the values entered ---- - tableOutput("values") + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Table summarizing the values entered ---- + tableOutput("values") + + ) + ) ) # Define server logic for slider examples ---- diff --git a/inst/examples/06_tabsets/Readme.md b/inst/examples/06_tabsets/Readme.md index 5dac839728..c548d306d0 100644 --- a/inst/examples/06_tabsets/Readme.md +++ b/inst/examples/06_tabsets/Readme.md @@ -1,4 +1,4 @@ -This example demonstrates the `navset_*` and `nav_panel` widgets from the `bslib` package. +This example demonstrates the `tabsetPanel` and `tabPanel` widgets. Notice that outputs that are not visible are not re-evaluated until they become visible. Try this: diff --git a/inst/examples/06_tabsets/app.R b/inst/examples/06_tabsets/app.R index 33e485d8ae..e1b89d6644 100644 --- a/inst/examples/06_tabsets/app.R +++ b/inst/examples/06_tabsets/app.R @@ -1,44 +1,47 @@ library(shiny) -library(bslib) # Define UI for random distribution app ---- -# Sidebar layout with input and output definitions ---- -ui <- page_sidebar( +ui <- fluidPage( # App title ---- - title ="Tabsets", - - # Sidebar panel for inputs ---- - sidebar = sidebar( - - # Input: Select the random distribution type ---- - radioButtons("dist", "Distribution type:", - c("Normal" = "norm", - "Uniform" = "unif", - "Log-normal" = "lnorm", - "Exponential" = "exp")), - # br() element to introduce extra vertical spacing ---- - br(), - # Input: Slider for the number of observations to generate ---- - sliderInput("n", - "Number of observations:", - value = 500, - min = 1, - max = 1000) - ), - - # Main panel for displaying outputs ---- - # Output: A tabset that combines three panels ---- - navset_card_underline( - - # Panel with plot ---- - nav_panel("Plot", plotOutput("plot")), - - # Panel with summary ---- - nav_panel("Summary", verbatimTextOutput("summary")), - - # Panel with table ---- - nav_panel("Table", tableOutput("table")) + titlePanel("Tabsets"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- + sidebarPanel( + + # Input: Select the random distribution type ---- + radioButtons("dist", "Distribution type:", + c("Normal" = "norm", + "Uniform" = "unif", + "Log-normal" = "lnorm", + "Exponential" = "exp")), + + # br() element to introduce extra vertical spacing ---- + br(), + + # Input: Slider for the number of observations to generate ---- + sliderInput("n", + "Number of observations:", + value = 500, + min = 1, + max = 1000) + + ), + + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Tabset w/ plot, summary, and table ---- + tabsetPanel(type = "tabs", + tabPanel("Plot", plotOutput("plot")), + tabPanel("Summary", verbatimTextOutput("summary")), + tabPanel("Table", tableOutput("table")) + ) + + ) ) ) diff --git a/inst/examples/07_widgets/app.R b/inst/examples/07_widgets/app.R index acf92a0d71..4ad8e88e7e 100644 --- a/inst/examples/07_widgets/app.R +++ b/inst/examples/07_widgets/app.R @@ -1,14 +1,16 @@ library(shiny) -library(bslib) -# Define UI for slider demo app ---- -ui <- page_sidebar( +# Define UI for dataset viewer app ---- +ui <- fluidPage( # App title ---- - title = "More Widgets", - # Sidebar panel for inputs ---- - sidebar = - sidebar( + titlePanel("More Widgets"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- + sidebarPanel( # Input: Select a dataset ---- selectInput("dataset", "Choose a dataset:", @@ -31,13 +33,19 @@ ui <- page_sidebar( ), - # Output: Header + summary of distribution ---- - h4("Summary"), - verbatimTextOutput("summary"), + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Header + summary of distribution ---- + h4("Summary"), + verbatimTextOutput("summary"), + + # Output: Header + table of distribution ---- + h4("Observations"), + tableOutput("view") + ) - # Output: Header + table of distribution ---- - h4("Observations"), - tableOutput("view") + ) ) # Define server logic to summarize and view selected dataset ---- diff --git a/inst/examples/09_upload/app.R b/inst/examples/09_upload/app.R index 50ec449a85..64d5ead234 100644 --- a/inst/examples/09_upload/app.R +++ b/inst/examples/09_upload/app.R @@ -1,14 +1,16 @@ library(shiny) -library(bslib) -# Define UI for slider demo app ---- -ui <- page_sidebar( +# Define UI for data upload app ---- +ui <- fluidPage( # App title ---- - title = "Uploading Files", - # Sidebar panel for inputs ---- - sidebar = - sidebar( + titlePanel("Uploading Files"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- + sidebarPanel( # Input: Select a file ---- fileInput("file1", "Choose CSV File", @@ -48,8 +50,15 @@ ui <- page_sidebar( ), - # Output: Data file ---- - tableOutput("contents") + # Main panel for displaying outputs ---- + mainPanel( + + # Output: Data file ---- + tableOutput("contents") + + ) + + ) ) # Define server logic to read selected file ---- diff --git a/inst/examples/10_download/app.R b/inst/examples/10_download/app.R index 8a778b77a8..b5a6dd1f22 100644 --- a/inst/examples/10_download/app.R +++ b/inst/examples/10_download/app.R @@ -1,14 +1,16 @@ library(shiny) -library(bslib) -# Define UI for slider demo app ---- -ui <- page_sidebar( +# Define UI for data download app ---- +ui <- fluidPage( # App title ---- - title = "Downloading Data", - # Sidebar panel for inputs ---- - sidebar = - sidebar( + titlePanel("Downloading Data"), + + # Sidebar layout with input and output definitions ---- + sidebarLayout( + + # Sidebar panel for inputs ---- + sidebarPanel( # Input: Choose dataset ---- selectInput("dataset", "Choose a dataset:", @@ -19,7 +21,14 @@ ui <- page_sidebar( ), - tableOutput("table") + # Main panel for displaying outputs ---- + mainPanel( + + tableOutput("table") + + ) + + ) ) # Define server logic to display and download selected file ---- diff --git a/inst/examples/11_timer/app.R b/inst/examples/11_timer/app.R index f30a27996e..6aaf3792d9 100644 --- a/inst/examples/11_timer/app.R +++ b/inst/examples/11_timer/app.R @@ -1,8 +1,7 @@ library(shiny) -library(bslib) # Define UI for displaying current time ---- -ui <- page_fillable( +ui <- fluidPage( h2(textOutput("currentTime")) diff --git a/inst/examples/01_hello_legacy/DESCRIPTION b/inst/shiny/01_hello/DESCRIPTION similarity index 100% rename from inst/examples/01_hello_legacy/DESCRIPTION rename to inst/shiny/01_hello/DESCRIPTION diff --git a/inst/examples/01_hello_legacy/Readme.md b/inst/shiny/01_hello/Readme.md similarity index 100% rename from inst/examples/01_hello_legacy/Readme.md rename to inst/shiny/01_hello/Readme.md diff --git a/inst/examples/01_hello_legacy/app.R b/inst/shiny/01_hello/app.R similarity index 77% rename from inst/examples/01_hello_legacy/app.R rename to inst/shiny/01_hello/app.R index 887c50576d..a098a7b422 100644 --- a/inst/examples/01_hello_legacy/app.R +++ b/inst/shiny/01_hello/app.R @@ -1,34 +1,23 @@ library(shiny) +library(bslib) # Define UI for app that draws a histogram ---- -ui <- fluidPage( +ui <- page_sidebar( # App title ---- - titlePanel("Hello Shiny!"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- - sidebarPanel( - + title = "Hello Shiny!", + # Sidebar panel for inputs ---- + sidebar = + sidebar( # Input: Slider for the number of bins ---- sliderInput(inputId = "bins", label = "Number of bins:", min = 1, max = 50, value = 30) - ), - - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Histogram ---- - plotOutput(outputId = "distPlot") - - ) - ) + # Output: Histogram ---- + plotOutput(outputId = "distPlot") ) # Define server logic required to draw a histogram ---- diff --git a/inst/examples/02_text_legacy/DESCRIPTION b/inst/shiny/02_text/DESCRIPTION similarity index 100% rename from inst/examples/02_text_legacy/DESCRIPTION rename to inst/shiny/02_text/DESCRIPTION diff --git a/inst/examples/02_text_legacy/Readme.md b/inst/shiny/02_text/Readme.md similarity index 100% rename from inst/examples/02_text_legacy/Readme.md rename to inst/shiny/02_text/Readme.md diff --git a/inst/examples/02_text_legacy/app.R b/inst/shiny/02_text/app.R similarity index 71% rename from inst/examples/02_text_legacy/app.R rename to inst/shiny/02_text/app.R index 9aff1e850c..839dbe50bf 100644 --- a/inst/examples/02_text_legacy/app.R +++ b/inst/shiny/02_text/app.R @@ -1,17 +1,15 @@ library(shiny) +library(bslib) # Define UI for dataset viewer app ---- -ui <- fluidPage( +ui <- page_sidebar( # App title ---- - titlePanel("Shiny Text"), - - # Sidebar layout with a input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- - sidebarPanel( + title = "Shiny Text", + # Sidebar panel for inputs ---- + sidebar = + sidebar( # Input: Selector for choosing dataset ---- selectInput(inputId = "dataset", label = "Choose a dataset:", @@ -22,18 +20,11 @@ ui <- fluidPage( label = "Number of observations to view:", value = 10) ), + # Output: Verbatim text for data summary ---- + verbatimTextOutput("summary"), - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Verbatim text for data summary ---- - verbatimTextOutput("summary"), - - # Output: HTML table with requested number of observations ---- - tableOutput("view") - - ) - ) + # Output: HTML table with requested number of observations ---- + tableOutput("view") ) # Define server logic to summarize and view selected dataset ---- diff --git a/inst/examples/03_reactivity_legacy/DESCRIPTION b/inst/shiny/03_reactivity/DESCRIPTION similarity index 100% rename from inst/examples/03_reactivity_legacy/DESCRIPTION rename to inst/shiny/03_reactivity/DESCRIPTION diff --git a/inst/examples/03_reactivity_legacy/Readme.md b/inst/shiny/03_reactivity/Readme.md similarity index 100% rename from inst/examples/03_reactivity_legacy/Readme.md rename to inst/shiny/03_reactivity/Readme.md diff --git a/inst/examples/03_reactivity_legacy/app.R b/inst/shiny/03_reactivity/app.R similarity index 82% rename from inst/examples/03_reactivity_legacy/app.R rename to inst/shiny/03_reactivity/app.R index 393ebfe619..7f08cfd221 100644 --- a/inst/examples/03_reactivity_legacy/app.R +++ b/inst/shiny/03_reactivity/app.R @@ -1,16 +1,14 @@ library(shiny) +library(bslib) # Define UI for dataset viewer app ---- -ui <- fluidPage( +ui <- page_sidebar( # App title ---- - titlePanel("Reactivity"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- - sidebarPanel( + title = "Reactivity", + # Sidebar panel for inputs ---- + sidebar = + sidebar( # Input: Text for providing a caption ---- # Note: Changes made to the caption in the textInput control @@ -31,20 +29,14 @@ ui <- fluidPage( ), - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Formatted text for caption ---- - h3(textOutput("caption", container = span)), - - # Output: Verbatim text for data summary ---- - verbatimTextOutput("summary"), + # Output: Formatted text for caption ---- + h3(textOutput("caption", container = span)), - # Output: HTML table with requested number of observations ---- - tableOutput("view") + # Output: Verbatim text for data summary ---- + verbatimTextOutput("summary"), - ) - ) + # Output: HTML table with requested number of observations ---- + tableOutput("view") ) # Define server logic to summarize and view selected dataset ---- diff --git a/inst/examples/04_mpg_legacy/DESCRIPTION b/inst/shiny/04_mpg/DESCRIPTION similarity index 100% rename from inst/examples/04_mpg_legacy/DESCRIPTION rename to inst/shiny/04_mpg/DESCRIPTION diff --git a/inst/examples/04_mpg_legacy/Readme.md b/inst/shiny/04_mpg/Readme.md similarity index 100% rename from inst/examples/04_mpg_legacy/Readme.md rename to inst/shiny/04_mpg/Readme.md diff --git a/inst/examples/04_mpg_legacy/app.R b/inst/shiny/04_mpg/app.R similarity index 79% rename from inst/examples/04_mpg_legacy/app.R rename to inst/shiny/04_mpg/app.R index e789bedcc9..6357c02ca3 100644 --- a/inst/examples/04_mpg_legacy/app.R +++ b/inst/shiny/04_mpg/app.R @@ -1,4 +1,5 @@ library(shiny) +library(bslib) library(datasets) # Data pre-processing ---- @@ -10,15 +11,12 @@ mpgData$am <- factor(mpgData$am, labels = c("Automatic", "Manual")) # Define UI for miles per gallon app ---- -ui <- fluidPage( +ui <- page_sidebar( # App title ---- - titlePanel("Miles Per Gallon"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- + title = "Miles Per Gallon", + # Sidebar panel for inputs ---- + sidebar = sidebarPanel( # Input: Selector for variable to plot against mpg ---- @@ -32,17 +30,11 @@ ui <- fluidPage( ), - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Formatted text for caption ---- - h3(textOutput("caption")), - - # Output: Plot of the requested variable against mpg ---- - plotOutput("mpgPlot") + # Output: Formatted text for caption ---- + h3(textOutput("caption")), - ) - ) + # Output: Plot of the requested variable against mpg ---- + plotOutput("mpgPlot") ) # Define server logic to plot various variables against mpg ---- diff --git a/inst/examples/05_sliders_legacy/DESCRIPTION b/inst/shiny/05_sliders/DESCRIPTION similarity index 100% rename from inst/examples/05_sliders_legacy/DESCRIPTION rename to inst/shiny/05_sliders/DESCRIPTION diff --git a/inst/examples/05_sliders_legacy/Readme.md b/inst/shiny/05_sliders/Readme.md similarity index 100% rename from inst/examples/05_sliders_legacy/Readme.md rename to inst/shiny/05_sliders/Readme.md diff --git a/inst/examples/05_sliders_legacy/app.R b/inst/shiny/05_sliders/app.R similarity index 84% rename from inst/examples/05_sliders_legacy/app.R rename to inst/shiny/05_sliders/app.R index d9aa05c727..eb6e86181e 100644 --- a/inst/examples/05_sliders_legacy/app.R +++ b/inst/shiny/05_sliders/app.R @@ -1,16 +1,14 @@ library(shiny) +library(bslib) # Define UI for slider demo app ---- -ui <- fluidPage( +ui <- page_sidebar( # App title ---- - titlePanel("Sliders"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar to demonstrate various slider options ---- - sidebarPanel( + title = "Sliders", + # Sidebar panel for inputs ---- + sidebar = + sidebar( # Input: Simple integer interval ---- sliderInput("integer", "Integer:", @@ -44,14 +42,8 @@ ui <- fluidPage( ), - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Table summarizing the values entered ---- - tableOutput("values") - - ) - ) + # Output: Table summarizing the values entered ---- + tableOutput("values") ) # Define server logic for slider examples ---- diff --git a/inst/examples/06_tabsets_legacy/DESCRIPTION b/inst/shiny/06_tabsets/DESCRIPTION similarity index 100% rename from inst/examples/06_tabsets_legacy/DESCRIPTION rename to inst/shiny/06_tabsets/DESCRIPTION diff --git a/inst/examples/06_tabsets_legacy/Readme.md b/inst/shiny/06_tabsets/Readme.md similarity index 85% rename from inst/examples/06_tabsets_legacy/Readme.md rename to inst/shiny/06_tabsets/Readme.md index c548d306d0..5dac839728 100644 --- a/inst/examples/06_tabsets_legacy/Readme.md +++ b/inst/shiny/06_tabsets/Readme.md @@ -1,4 +1,4 @@ -This example demonstrates the `tabsetPanel` and `tabPanel` widgets. +This example demonstrates the `navset_*` and `nav_panel` widgets from the `bslib` package. Notice that outputs that are not visible are not re-evaluated until they become visible. Try this: diff --git a/inst/examples/06_tabsets_legacy/app.R b/inst/shiny/06_tabsets/app.R similarity index 54% rename from inst/examples/06_tabsets_legacy/app.R rename to inst/shiny/06_tabsets/app.R index e1b89d6644..33e485d8ae 100644 --- a/inst/examples/06_tabsets_legacy/app.R +++ b/inst/shiny/06_tabsets/app.R @@ -1,47 +1,44 @@ library(shiny) +library(bslib) # Define UI for random distribution app ---- -ui <- fluidPage( +# Sidebar layout with input and output definitions ---- +ui <- page_sidebar( # App title ---- - titlePanel("Tabsets"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- - sidebarPanel( - - # Input: Select the random distribution type ---- - radioButtons("dist", "Distribution type:", - c("Normal" = "norm", - "Uniform" = "unif", - "Log-normal" = "lnorm", - "Exponential" = "exp")), - - # br() element to introduce extra vertical spacing ---- - br(), - - # Input: Slider for the number of observations to generate ---- - sliderInput("n", - "Number of observations:", - value = 500, - min = 1, - max = 1000) - - ), - - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Tabset w/ plot, summary, and table ---- - tabsetPanel(type = "tabs", - tabPanel("Plot", plotOutput("plot")), - tabPanel("Summary", verbatimTextOutput("summary")), - tabPanel("Table", tableOutput("table")) - ) - - ) + title ="Tabsets", + + # Sidebar panel for inputs ---- + sidebar = sidebar( + + # Input: Select the random distribution type ---- + radioButtons("dist", "Distribution type:", + c("Normal" = "norm", + "Uniform" = "unif", + "Log-normal" = "lnorm", + "Exponential" = "exp")), + # br() element to introduce extra vertical spacing ---- + br(), + # Input: Slider for the number of observations to generate ---- + sliderInput("n", + "Number of observations:", + value = 500, + min = 1, + max = 1000) + ), + + # Main panel for displaying outputs ---- + # Output: A tabset that combines three panels ---- + navset_card_underline( + + # Panel with plot ---- + nav_panel("Plot", plotOutput("plot")), + + # Panel with summary ---- + nav_panel("Summary", verbatimTextOutput("summary")), + + # Panel with table ---- + nav_panel("Table", tableOutput("table")) ) ) diff --git a/inst/examples/07_widgets_legacy/DESCRIPTION b/inst/shiny/07_widgets/DESCRIPTION similarity index 100% rename from inst/examples/07_widgets_legacy/DESCRIPTION rename to inst/shiny/07_widgets/DESCRIPTION diff --git a/inst/examples/07_widgets_legacy/Readme.md b/inst/shiny/07_widgets/Readme.md similarity index 100% rename from inst/examples/07_widgets_legacy/Readme.md rename to inst/shiny/07_widgets/Readme.md diff --git a/inst/examples/07_widgets_legacy/app.R b/inst/shiny/07_widgets/app.R similarity index 78% rename from inst/examples/07_widgets_legacy/app.R rename to inst/shiny/07_widgets/app.R index 4ad8e88e7e..acf92a0d71 100644 --- a/inst/examples/07_widgets_legacy/app.R +++ b/inst/shiny/07_widgets/app.R @@ -1,16 +1,14 @@ library(shiny) +library(bslib) -# Define UI for dataset viewer app ---- -ui <- fluidPage( +# Define UI for slider demo app ---- +ui <- page_sidebar( # App title ---- - titlePanel("More Widgets"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- - sidebarPanel( + title = "More Widgets", + # Sidebar panel for inputs ---- + sidebar = + sidebar( # Input: Select a dataset ---- selectInput("dataset", "Choose a dataset:", @@ -33,19 +31,13 @@ ui <- fluidPage( ), - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Header + summary of distribution ---- - h4("Summary"), - verbatimTextOutput("summary"), - - # Output: Header + table of distribution ---- - h4("Observations"), - tableOutput("view") - ) + # Output: Header + summary of distribution ---- + h4("Summary"), + verbatimTextOutput("summary"), - ) + # Output: Header + table of distribution ---- + h4("Observations"), + tableOutput("view") ) # Define server logic to summarize and view selected dataset ---- diff --git a/inst/examples/08_html/DESCRIPTION b/inst/shiny/08_html/DESCRIPTION similarity index 100% rename from inst/examples/08_html/DESCRIPTION rename to inst/shiny/08_html/DESCRIPTION diff --git a/inst/examples/08_html/Readme.md b/inst/shiny/08_html/Readme.md similarity index 100% rename from inst/examples/08_html/Readme.md rename to inst/shiny/08_html/Readme.md diff --git a/inst/examples/08_html/app.R b/inst/shiny/08_html/app.R similarity index 100% rename from inst/examples/08_html/app.R rename to inst/shiny/08_html/app.R diff --git a/inst/examples/08_html/www/index.html b/inst/shiny/08_html/www/index.html similarity index 100% rename from inst/examples/08_html/www/index.html rename to inst/shiny/08_html/www/index.html diff --git a/inst/examples/09_upload_legacy/DESCRIPTION b/inst/shiny/09_upload/DESCRIPTION similarity index 100% rename from inst/examples/09_upload_legacy/DESCRIPTION rename to inst/shiny/09_upload/DESCRIPTION diff --git a/inst/examples/09_upload_legacy/Readme.md b/inst/shiny/09_upload/Readme.md similarity index 100% rename from inst/examples/09_upload_legacy/Readme.md rename to inst/shiny/09_upload/Readme.md diff --git a/inst/examples/09_upload_legacy/app.R b/inst/shiny/09_upload/app.R similarity index 83% rename from inst/examples/09_upload_legacy/app.R rename to inst/shiny/09_upload/app.R index 64d5ead234..50ec449a85 100644 --- a/inst/examples/09_upload_legacy/app.R +++ b/inst/shiny/09_upload/app.R @@ -1,16 +1,14 @@ library(shiny) +library(bslib) -# Define UI for data upload app ---- -ui <- fluidPage( +# Define UI for slider demo app ---- +ui <- page_sidebar( # App title ---- - titlePanel("Uploading Files"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- - sidebarPanel( + title = "Uploading Files", + # Sidebar panel for inputs ---- + sidebar = + sidebar( # Input: Select a file ---- fileInput("file1", "Choose CSV File", @@ -50,15 +48,8 @@ ui <- fluidPage( ), - # Main panel for displaying outputs ---- - mainPanel( - - # Output: Data file ---- - tableOutput("contents") - - ) - - ) + # Output: Data file ---- + tableOutput("contents") ) # Define server logic to read selected file ---- diff --git a/inst/examples/10_download_legacy/DESCRIPTION b/inst/shiny/10_download/DESCRIPTION similarity index 100% rename from inst/examples/10_download_legacy/DESCRIPTION rename to inst/shiny/10_download/DESCRIPTION diff --git a/inst/examples/10_download_legacy/Readme.md b/inst/shiny/10_download/Readme.md similarity index 100% rename from inst/examples/10_download_legacy/Readme.md rename to inst/shiny/10_download/Readme.md diff --git a/inst/examples/10_download_legacy/app.R b/inst/shiny/10_download/app.R similarity index 74% rename from inst/examples/10_download_legacy/app.R rename to inst/shiny/10_download/app.R index b5a6dd1f22..8a778b77a8 100644 --- a/inst/examples/10_download_legacy/app.R +++ b/inst/shiny/10_download/app.R @@ -1,16 +1,14 @@ library(shiny) +library(bslib) -# Define UI for data download app ---- -ui <- fluidPage( +# Define UI for slider demo app ---- +ui <- page_sidebar( # App title ---- - titlePanel("Downloading Data"), - - # Sidebar layout with input and output definitions ---- - sidebarLayout( - - # Sidebar panel for inputs ---- - sidebarPanel( + title = "Downloading Data", + # Sidebar panel for inputs ---- + sidebar = + sidebar( # Input: Choose dataset ---- selectInput("dataset", "Choose a dataset:", @@ -21,14 +19,7 @@ ui <- fluidPage( ), - # Main panel for displaying outputs ---- - mainPanel( - - tableOutput("table") - - ) - - ) + tableOutput("table") ) # Define server logic to display and download selected file ---- diff --git a/inst/examples/11_timer_legacy/DESCRIPTION b/inst/shiny/11_timer/DESCRIPTION similarity index 100% rename from inst/examples/11_timer_legacy/DESCRIPTION rename to inst/shiny/11_timer/DESCRIPTION diff --git a/inst/examples/11_timer_legacy/Readme.md b/inst/shiny/11_timer/Readme.md similarity index 100% rename from inst/examples/11_timer_legacy/Readme.md rename to inst/shiny/11_timer/Readme.md diff --git a/inst/examples/11_timer_legacy/app.R b/inst/shiny/11_timer/app.R similarity index 91% rename from inst/examples/11_timer_legacy/app.R rename to inst/shiny/11_timer/app.R index 6aaf3792d9..f30a27996e 100644 --- a/inst/examples/11_timer_legacy/app.R +++ b/inst/shiny/11_timer/app.R @@ -1,7 +1,8 @@ library(shiny) +library(bslib) # Define UI for displaying current time ---- -ui <- fluidPage( +ui <- page_fillable( h2(textOutput("currentTime")) From 0c1a39daf9362edfdf7faa742628637f7157acb8 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 2 Feb 2024 16:39:23 -0600 Subject: [PATCH 15/18] Update news --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index d362ff08eb..c1ccd370c9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ ## Breaking changes * Both `conditionalPanel()` and `uiOutput()` are now styled with `display: contents` by default in Shiny apps that use Bootstrap 5. This means that the elements they contain are positioned as if they were direct children of the parent container holding the `conditionalPanel()` or `uiOutput()`. This is probably what most users intend when they use these functions, but it may break apps that applied styles directly to the container elements created by these two functions. In that case, you may include CSS rules to set `display: block` for the `.shiny-panel-conditional` or `.shiny-html-output` classes. (#3957, #3960) +* The examples behind `runExample()` now use `{bslib}` to generate a better looking result. To instead run the "legacy" examples, set `options(shiny.legacy.examples = TRUE)` before calling `runExample()`. (#3963) ## New features and improvements From a78f6f9de170cd794608fc8c444496264832aa5c Mon Sep 17 00:00:00 2001 From: Carson Date: Wed, 13 Mar 2024 11:49:04 -0500 Subject: [PATCH 16/18] Fix some code formatting issues --- inst/shiny/01_hello/app.R | 23 ++++++++++++++--------- inst/shiny/02_text/app.R | 28 +++++++++++++++++----------- inst/shiny/03_reactivity/app.R | 19 +++++++++---------- inst/shiny/04_mpg/app.R | 14 +++++++------- inst/shiny/05_sliders/app.R | 10 +++++----- inst/shiny/06_tabsets/app.R | 2 +- inst/shiny/07_widgets/app.R | 18 +++++++++--------- inst/shiny/09_upload/app.R | 10 +++++----- inst/shiny/10_download/app.R | 8 ++++---- inst/shiny/11_timer/app.R | 4 +--- 10 files changed, 72 insertions(+), 64 deletions(-) diff --git a/inst/shiny/01_hello/app.R b/inst/shiny/01_hello/app.R index a098a7b422..4765171f6e 100644 --- a/inst/shiny/01_hello/app.R +++ b/inst/shiny/01_hello/app.R @@ -6,16 +6,21 @@ ui <- page_sidebar( # App title ---- title = "Hello Shiny!", + # Sidebar panel for inputs ---- - sidebar = - sidebar( - # Input: Slider for the number of bins ---- - sliderInput(inputId = "bins", - label = "Number of bins:", - min = 1, - max = 50, - value = 30) - ), + sidebar = sidebar( + + # Input: Slider for the number of bins ---- + sliderInput( + inputId = "bins", + label = "Number of bins:", + min = 1, + max = 50, + value = 30 + ) + + ), + # Output: Histogram ---- plotOutput(outputId = "distPlot") ) diff --git a/inst/shiny/02_text/app.R b/inst/shiny/02_text/app.R index 839dbe50bf..d69b092e2d 100644 --- a/inst/shiny/02_text/app.R +++ b/inst/shiny/02_text/app.R @@ -8,18 +8,24 @@ ui <- page_sidebar( title = "Shiny Text", # Sidebar panel for inputs ---- - sidebar = - sidebar( - # Input: Selector for choosing dataset ---- - selectInput(inputId = "dataset", - label = "Choose a dataset:", - choices = c("rock", "pressure", "cars")), - - # Input: Numeric entry for number of obs to view ---- - numericInput(inputId = "obs", - label = "Number of observations to view:", - value = 10) + sidebar = sidebar( + + # Input: Selector for choosing dataset ---- + selectInput( + inputId = "dataset", + label = "Choose a dataset:", + choices = c("rock", "pressure", "cars") ), + + # Input: Numeric entry for number of obs to view ---- + numericInput( + inputId = "obs", + label = "Number of observations to view:", + value = 10 + ) + + ), + # Output: Verbatim text for data summary ---- verbatimTextOutput("summary"), diff --git a/inst/shiny/03_reactivity/app.R b/inst/shiny/03_reactivity/app.R index 7f08cfd221..789c0ddba5 100644 --- a/inst/shiny/03_reactivity/app.R +++ b/inst/shiny/03_reactivity/app.R @@ -6,9 +6,9 @@ ui <- page_sidebar( # App title ---- title = "Reactivity", + # Sidebar panel for inputs ---- - sidebar = - sidebar( + sidebar = sidebar( # Input: Text for providing a caption ---- # Note: Changes made to the caption in the textInput control @@ -26,17 +26,16 @@ ui <- page_sidebar( numericInput(inputId = "obs", label = "Number of observations to view:", value = 10) + ), - ), - - # Output: Formatted text for caption ---- - h3(textOutput("caption", container = span)), + # Output: Formatted text for caption ---- + h3(textOutput("caption", container = span)), - # Output: Verbatim text for data summary ---- - verbatimTextOutput("summary"), + # Output: Verbatim text for data summary ---- + verbatimTextOutput("summary"), - # Output: HTML table with requested number of observations ---- - tableOutput("view") + # Output: HTML table with requested number of observations ---- + tableOutput("view") ) # Define server logic to summarize and view selected dataset ---- diff --git a/inst/shiny/04_mpg/app.R b/inst/shiny/04_mpg/app.R index 6357c02ca3..6b86ddacbd 100644 --- a/inst/shiny/04_mpg/app.R +++ b/inst/shiny/04_mpg/app.R @@ -15,9 +15,9 @@ ui <- page_sidebar( # App title ---- title = "Miles Per Gallon", + # Sidebar panel for inputs ---- - sidebar = - sidebarPanel( + sidebar = sidebar( # Input: Selector for variable to plot against mpg ---- selectInput("variable", "Variable:", @@ -28,13 +28,13 @@ ui <- page_sidebar( # Input: Checkbox for whether outliers should be included ---- checkboxInput("outliers", "Show outliers", TRUE) - ), + ), - # Output: Formatted text for caption ---- - h3(textOutput("caption")), + # Output: Formatted text for caption ---- + h3(textOutput("caption")), - # Output: Plot of the requested variable against mpg ---- - plotOutput("mpgPlot") + # Output: Plot of the requested variable against mpg ---- + plotOutput("mpgPlot") ) # Define server logic to plot various variables against mpg ---- diff --git a/inst/shiny/05_sliders/app.R b/inst/shiny/05_sliders/app.R index eb6e86181e..14b5d278ac 100644 --- a/inst/shiny/05_sliders/app.R +++ b/inst/shiny/05_sliders/app.R @@ -6,9 +6,9 @@ ui <- page_sidebar( # App title ---- title = "Sliders", + # Sidebar panel for inputs ---- - sidebar = - sidebar( + sidebar = sidebar( # Input: Simple integer interval ---- sliderInput("integer", "Integer:", @@ -40,10 +40,10 @@ ui <- page_sidebar( animate = animationOptions(interval = 300, loop = TRUE)) - ), + ), - # Output: Table summarizing the values entered ---- - tableOutput("values") + # Output: Table summarizing the values entered ---- + tableOutput("values") ) # Define server logic for slider examples ---- diff --git a/inst/shiny/06_tabsets/app.R b/inst/shiny/06_tabsets/app.R index 33e485d8ae..63e8f9f0e3 100644 --- a/inst/shiny/06_tabsets/app.R +++ b/inst/shiny/06_tabsets/app.R @@ -6,7 +6,7 @@ library(bslib) ui <- page_sidebar( # App title ---- - title ="Tabsets", + title = "Tabsets", # Sidebar panel for inputs ---- sidebar = sidebar( diff --git a/inst/shiny/07_widgets/app.R b/inst/shiny/07_widgets/app.R index acf92a0d71..66d337c3be 100644 --- a/inst/shiny/07_widgets/app.R +++ b/inst/shiny/07_widgets/app.R @@ -6,9 +6,9 @@ ui <- page_sidebar( # App title ---- title = "More Widgets", + # Sidebar panel for inputs ---- - sidebar = - sidebar( + sidebar = sidebar( # Input: Select a dataset ---- selectInput("dataset", "Choose a dataset:", @@ -29,15 +29,15 @@ ui <- page_sidebar( # time-consuming. actionButton("update", "Update View") - ), + ), - # Output: Header + summary of distribution ---- - h4("Summary"), - verbatimTextOutput("summary"), + # Output: Header + summary of distribution ---- + h4("Summary"), + verbatimTextOutput("summary"), - # Output: Header + table of distribution ---- - h4("Observations"), - tableOutput("view") + # Output: Header + table of distribution ---- + h4("Observations"), + tableOutput("view") ) # Define server logic to summarize and view selected dataset ---- diff --git a/inst/shiny/09_upload/app.R b/inst/shiny/09_upload/app.R index 50ec449a85..d4cbfad459 100644 --- a/inst/shiny/09_upload/app.R +++ b/inst/shiny/09_upload/app.R @@ -6,9 +6,9 @@ ui <- page_sidebar( # App title ---- title = "Uploading Files", + # Sidebar panel for inputs ---- - sidebar = - sidebar( + sidebar = sidebar( # Input: Select a file ---- fileInput("file1", "Choose CSV File", @@ -46,10 +46,10 @@ ui <- page_sidebar( All = "all"), selected = "head") - ), + ), - # Output: Data file ---- - tableOutput("contents") + # Output: Data file ---- + tableOutput("contents") ) # Define server logic to read selected file ---- diff --git a/inst/shiny/10_download/app.R b/inst/shiny/10_download/app.R index 8a778b77a8..641e16f6a1 100644 --- a/inst/shiny/10_download/app.R +++ b/inst/shiny/10_download/app.R @@ -6,9 +6,9 @@ ui <- page_sidebar( # App title ---- title = "Downloading Data", + # Sidebar panel for inputs ---- - sidebar = - sidebar( + sidebar = sidebar( # Input: Choose dataset ---- selectInput("dataset", "Choose a dataset:", @@ -17,9 +17,9 @@ ui <- page_sidebar( # Button downloadButton("downloadData", "Download") - ), + ), - tableOutput("table") + tableOutput("table") ) # Define server logic to display and download selected file ---- diff --git a/inst/shiny/11_timer/app.R b/inst/shiny/11_timer/app.R index f30a27996e..0ec5f98591 100644 --- a/inst/shiny/11_timer/app.R +++ b/inst/shiny/11_timer/app.R @@ -2,10 +2,8 @@ library(shiny) library(bslib) # Define UI for displaying current time ---- -ui <- page_fillable( - +ui <- page_fluid( h2(textOutput("currentTime")) - ) # Define server logic to show current time, update every second ---- From 81f489a344fce47952b7d9952634659a99a5efb0 Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Tue, 19 Mar 2024 18:02:40 -0500 Subject: [PATCH 17/18] Update NEWS.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 6c82daebbc..b074017cf5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ * `renderDataTable()`/`dataTableOutput()` are officially deprecated in favor of [their `{DT}` equivalents](https://rstudio.github.io/DT/shiny.html), `renderDT()`/`DTOutput()`. In most cases, simply changing `renderDataTable()` to `DT::renderDT()` and `dataTableOutput()` to `DT::DTOutput()` is sufficient for upgrading. Also, to promote migration, when a recent version of `{DT}` is available, `renderDataTable()`/`dataTableOutput()` now automatically use their `{DT}` equivalent (and provide a message that they are doing so). If this happens to degrade an existing app, set `options(shiny.legacy.datatable = TRUE)` to get the old (i.e., non-`{DT}`) implementation. (#3998) * Both `conditionalPanel()` and `uiOutput()` are now styled with `display: contents` by default in Shiny apps that use Bootstrap 5. This means that the elements they contain are positioned as if they were direct children of the parent container holding the `conditionalPanel()` or `uiOutput()`. This is probably what most users intend when they use these functions, but it may break apps that applied styles directly to the container elements created by these two functions. In that case, you may include CSS rules to set `display: block` for the `.shiny-panel-conditional` or `.shiny-html-output` classes. (#3957, #3960) + * The examples behind `runExample()` now use `{bslib}` to generate a better looking result. To instead run the "legacy" examples, set `options(shiny.legacy.examples = TRUE)` before calling `runExample()`. (#3963) ## New features and improvements From 7db02cbd679f460ff61f4f532929b604198275f0 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 19 Mar 2024 17:59:11 -0500 Subject: [PATCH 18/18] Don't default to showcase mode --- inst/shiny/01_hello/DESCRIPTION | 1 - inst/shiny/02_text/DESCRIPTION | 2 -- inst/shiny/03_reactivity/DESCRIPTION | 1 - inst/shiny/04_mpg/DESCRIPTION | 1 - inst/shiny/05_sliders/DESCRIPTION | 1 - inst/shiny/06_tabsets/DESCRIPTION | 1 - inst/shiny/07_widgets/DESCRIPTION | 1 - inst/shiny/08_html/DESCRIPTION | 1 - inst/shiny/09_upload/DESCRIPTION | 1 - inst/shiny/10_download/DESCRIPTION | 1 - inst/shiny/11_timer/DESCRIPTION | 1 - 11 files changed, 12 deletions(-) diff --git a/inst/shiny/01_hello/DESCRIPTION b/inst/shiny/01_hello/DESCRIPTION index fd1d5a5280..62734b6047 100644 --- a/inst/shiny/01_hello/DESCRIPTION +++ b/inst/shiny/01_hello/DESCRIPTION @@ -2,6 +2,5 @@ Title: Hello Shiny! Author: RStudio, Inc. AuthorUrl: http://www.rstudio.com/ License: MIT -DisplayMode: Showcase Tags: getting-started Type: Shiny diff --git a/inst/shiny/02_text/DESCRIPTION b/inst/shiny/02_text/DESCRIPTION index 8f62a976a7..519d8790d8 100644 --- a/inst/shiny/02_text/DESCRIPTION +++ b/inst/shiny/02_text/DESCRIPTION @@ -2,7 +2,5 @@ Title: Shiny Text Author: RStudio, Inc. AuthorUrl: http://www.rstudio.com/ License: MIT -DisplayMode: Showcase Tags: getting-started Type: Shiny - diff --git a/inst/shiny/03_reactivity/DESCRIPTION b/inst/shiny/03_reactivity/DESCRIPTION index 01db04d4ad..623d270ecf 100644 --- a/inst/shiny/03_reactivity/DESCRIPTION +++ b/inst/shiny/03_reactivity/DESCRIPTION @@ -2,6 +2,5 @@ Title: Reactivity Author: RStudio, Inc. AuthorUrl: http://www.rstudio.com/ License: MIT -DisplayMode: Showcase Tags: getting-started Type: Shiny diff --git a/inst/shiny/04_mpg/DESCRIPTION b/inst/shiny/04_mpg/DESCRIPTION index 324145bbd7..e8d46b3990 100644 --- a/inst/shiny/04_mpg/DESCRIPTION +++ b/inst/shiny/04_mpg/DESCRIPTION @@ -2,6 +2,5 @@ Title: Miles Per Gallon Author: RStudio, Inc. AuthorUrl: http://www.rstudio.com/ License: MIT -DisplayMode: Showcase Tags: getting-started Type: Shiny diff --git a/inst/shiny/05_sliders/DESCRIPTION b/inst/shiny/05_sliders/DESCRIPTION index 954fddbf21..ee1ab9cb0c 100644 --- a/inst/shiny/05_sliders/DESCRIPTION +++ b/inst/shiny/05_sliders/DESCRIPTION @@ -2,6 +2,5 @@ Title: Sliders Author: RStudio, Inc. AuthorUrl: http://www.rstudio.com/ License: MIT -DisplayMode: Showcase Tags: getting-started Type: Shiny diff --git a/inst/shiny/06_tabsets/DESCRIPTION b/inst/shiny/06_tabsets/DESCRIPTION index 52c09c57ad..71bed385be 100644 --- a/inst/shiny/06_tabsets/DESCRIPTION +++ b/inst/shiny/06_tabsets/DESCRIPTION @@ -2,6 +2,5 @@ Title: Tabsets Author: RStudio, Inc. AuthorUrl: http://www.rstudio.com/ License: MIT -DisplayMode: Showcase Tags: getting-started Type: Shiny diff --git a/inst/shiny/07_widgets/DESCRIPTION b/inst/shiny/07_widgets/DESCRIPTION index b2ad51f7ce..d66a2255ee 100644 --- a/inst/shiny/07_widgets/DESCRIPTION +++ b/inst/shiny/07_widgets/DESCRIPTION @@ -2,6 +2,5 @@ Title: Widgets Author: RStudio, Inc. AuthorUrl: http://www.rstudio.com/ License: MIT -DisplayMode: Showcase Tags: getting-started Type: Shiny diff --git a/inst/shiny/08_html/DESCRIPTION b/inst/shiny/08_html/DESCRIPTION index 76a9c2187c..3cf00e3490 100644 --- a/inst/shiny/08_html/DESCRIPTION +++ b/inst/shiny/08_html/DESCRIPTION @@ -2,6 +2,5 @@ Title: Custom HTML UI Author: RStudio, Inc. AuthorUrl: http://www.rstudio.com/ License: MIT -DisplayMode: Showcase Tags: getting-started Type: Shiny diff --git a/inst/shiny/09_upload/DESCRIPTION b/inst/shiny/09_upload/DESCRIPTION index b5e24c3a13..a92e716b27 100644 --- a/inst/shiny/09_upload/DESCRIPTION +++ b/inst/shiny/09_upload/DESCRIPTION @@ -2,6 +2,5 @@ Title: File Upload Author: RStudio, Inc. AuthorUrl: http://www.rstudio.com/ License: MIT -DisplayMode: Showcase Tags: getting-started Type: Shiny diff --git a/inst/shiny/10_download/DESCRIPTION b/inst/shiny/10_download/DESCRIPTION index 3eb34a7f8e..30eaae74ce 100644 --- a/inst/shiny/10_download/DESCRIPTION +++ b/inst/shiny/10_download/DESCRIPTION @@ -2,6 +2,5 @@ Title: File Download Author: RStudio, Inc. AuthorUrl: http://www.rstudio.com/ License: MIT -DisplayMode: Showcase Tags: getting-started Type: Shiny diff --git a/inst/shiny/11_timer/DESCRIPTION b/inst/shiny/11_timer/DESCRIPTION index 3412d2f96c..4fe2244e91 100644 --- a/inst/shiny/11_timer/DESCRIPTION +++ b/inst/shiny/11_timer/DESCRIPTION @@ -2,6 +2,5 @@ Title: Timer Author: RStudio, Inc. AuthorUrl: http://www.rstudio.com/ License: MIT -DisplayMode: Showcase Tags: getting-started Type: Shiny