Using the downloadFile Shiny Module



This Shiny Module was created in order to provide a consistent-looking and easy-to-use button that facilitates one or multiple types of file downloads.



Shiny Module Overview

Shiny modules consist of a pair of functions that modularize, or package, a small piece of reusable functionality. The UI function is called directly by the user to place the UI in the correct location (as with other shiny UI objects). The server function is not called directly by the user of the module. Instead the module server function is called only once to set it up using the shiny::callModule function inside the server function (i.e. user-local session scope. The callModule function supplies the first three arguments of the Shiny Module's function inputs - the input, output, and session. Additional arguments supplied by the user in the callModule function are passed to the specific shiny module that is called. There can be additional helper functions that are a part of a shiny module.

The downloadFile Shiny Module is a part of the periscope package and consists of the following functions:


The downloadFileButton function is called from the ui.R (or equivalent) file in the location where the button should be placed. This is similar to other UI element placement in shiny.

The downloadFileButton function takes the unique object ID for the UI object as well as a list of file types the button will allow the user to request and the tooltip text.

If only one type is given the button will be a single-download type of button that starts the specified download when the button is pressed. The button will look like:

If more than one type is given there will be a dropdown choice given to the user when the button is pressed and the download will start when the choose one of the types. The dropdown choices will be in the order given by the call to the function. The button and dropdown will look like:

# Inside ui_body.R or ui_sidebar.R

#single download type
                   downloadtypes = c("csv"), 
                   hovertext = "Button 1 Tooltip")

#multiple download types
                   downloadtypes = c("csv", "tsv"), 
                   hovertext = "Button 2 Tooltip")


The downloadFile function is not called directly - instead a call to shiny::callModule is made inside the server.R (or equivalent) file to initialize the module.

The call consists of the following:

Data Function Requirements

# Inside server_local.R

#single download type
           logger = ss_userAction.Log,
           filenameroot = "mydownload1",
           datafxns = list(csv = mydatafxn1),
           aspectratio = 1)

#multiple download types
           logger = ss_userAction.Log,
           filenameroot = "mytype2",
           datafxns = list(csv = mydatafxn1, xlsx = mydatafxn2),
           aspectratio = 1)

Sample Application

For a complete running shiny example application using the downloadableTable module you can create and run a periscope sample application using:


app_dir = tempdir()
create_new_application('mysampleapp', location = app_dir, sampleapp = TRUE)
runApp('mysampleapp', appDir = app_dir)

Additional Resources


Try the periscope package in your browser

Any scripts or data that you put into this service are public.

periscope documentation built on July 8, 2020, 7:18 p.m.