Package 'shinyhttr'

Title: Progress Bars for Downloads in 'shiny' Apps
Description: Modifies the progress() function from 'httr' package to let it send output to progressBar() function from 'shinyWidgets' package. It is just a tweak at the original functions from 'httr' package to make it smooth for 'shiny' developers.
Authors: Athos Damiani [aut, cre], Hadley Wickham [aut], RStudio [cph]
Maintainer: Athos Damiani <[email protected]>
License: MIT + file LICENSE
Version: 1.1.0
Built: 2024-11-21 03:04:07 UTC
Source: https://github.com/curso-r/shinyhttr

Help Index


Add a progress bar compatible with 'shinyWidgets::updateProgressBar()'.

Description

Add a progress bar to request just like the vanilla 'httr::progress()' but with capability to talk to 'shinyWidgets::updateProgressBar()' by giving the session and id arguments to it.

Usage

progress(
  session,
  id,
  type = c("down", "up"),
  con = stdout(),
  title = NULL,
  status = NULL,
  range_value = NULL,
  unit_mark = "%"
)

Arguments

session

(from ‘shinyWidgets::updateProgressBar()“ doc) The ’session' object passed to function given to shinyServer.

id

(from 'shinyWidgets::updateProgressBar()' doc) An id used to update the progress bar.

type

(from 'httr::progress()“ doc) Type of progress to display: either number of bytes uploaded or downloaded.

con

(from 'httr::progress()' doc) Connection to send output too. Usually stdout() or stderr.

title

(from 'shinyWidgets::updateProgressBar()' doc) character, optional title.

status

(from 'shinyWidgets::updateProgressBar()' doc) Color, must be a valid Bootstrap status : primary, info, success, warning, danger.

range_value

(from 'shinyWidgets::updateProgressBar()' doc) Default is to display percentage ([0, 100]), but you can specify a custom range, e.g. -50, 50.

unit_mark

(from 'shinyWidgets::updateProgressBar()' doc) Unit for value displayed on the progress bar, default to "%".

See Also

progress, progressBar, updateProgressBar

Examples

if (interactive()) {
  
  library(shiny)
  library(shinyWidgets)
  library(shinyhttr)
  
  ui <- fluidPage(
    
    sidebarLayout(
      
      NULL,
      
      mainPanel(
        actionButton('download', 'Download 100MB file...'),
        tags$p("see R console to compare both progress bars."),
        progressBar(
          id = "pb",
          value = 0,
          title = "",
          display_pct = TRUE
        )
      )
    )
  )
  
  server <- function(input, output, session) {
    observeEvent(input$download, {
      httr::GET(
        url = "https://speed.hetzner.de/100MB.bin",
        progress(session, id = "pb")
      )
    })
  }
  
  shinyApp(ui, server)
}

progress_bar

Description

Same as 'httr:::progress_bar()' but with capability to talk to 'shinyWidgets::progressBar()'.

Usage

progress_bar(
  type,
  con,
  session,
  id,
  title = NULL,
  status = NULL,
  range_value = NULL,
  unit_mark = "%"
)

Arguments

type

(from 'httr::progress()' doc) Type of progress to display: either number of bytes uploaded or downloaded.

con

(from 'httr::progress()' doc) Connection to send output too. Usually stdout() or stderr.

session

(from ‘shinyWidgets::updateProgressBar()' doc) The ’session' object passed to function given to shinyServer.

id

(from 'shinyWidgets::updateProgressBar()' doc) An id used to update the progress bar.

title

(from 'shinyWidgets::updateProgressBar()' doc) character, optional title.

status

(from 'shinyWidgets::updateProgressBar()' doc) Color, must be a valid Bootstrap status : primary, info, success, warning, danger.

range_value

(from 'shinyWidgets::updateProgressBar()' doc) Default is to display percentage ([0, 100]), but you can specify a custom range, e.g. -50, 50.

unit_mark

(from 'shinyWidgets::updateProgressBar()' doc) Unit for value displayed on the progress bar, default to "%".

Value

a function with rules to print out the progress.

See Also

progress, progressBar


runExample

Description

Launch shiny example application using shinyhttr::progress_bar. This app also uses module to show that it works with it too.

Usage

runExample(display.mode = "showcase")

Arguments

display.mode

The mode in which to display the example. Defaults to showcase, but may be set to normal to see the example without code or commentary.