View source: R/downloadableTable.R
downloadableTable | R Documentation |
Server-side function for the downloadableTableUI. This is a custom high-functionality table paired with a linked downloadFile button.
downloadableTable(
id,
logger = NULL,
filenameroot = "download",
downloaddatafxns = NULL,
tabledata,
selection = NULL,
table_options = list()
)
id |
the ID of the Module's UI element |
logger |
logger to use |
filenameroot |
the text used for user-downloaded file - can be either a character string, a reactive expression or a function returning a character string |
downloaddatafxns |
a named list of functions providing the data as return values. The names for the list should be the same names that were used when the table UI was created. |
tabledata |
function or reactive expression providing the table display data as a return value. This function should require no input parameters. |
selection |
function or reactive expression providing the row_ids of the rows that should be selected |
table_options |
optional table formatting parameters check |
downloadFile button will be hidden if downloadableTable
parameter downloaddatafxn
or
downloadableTableUI
parameter downloadtypes
is empty
Generated table can highly customized using function ?DT::datatable
same arguments
except for options
and selection
parameters.
For options
user can pass the same ?DT::datatable
options using the same names and
values one by one separated by comma.
For selection
parameter it can be either a function or reactive expression providing the row_ids of the
rows that should be selected.
Also, user can apply the same provided ?DT::formatCurrency
columns formats on passed
dataset using format functions names as keys and their options as a list.
Reactive expression containing the currently selected rows in the display table
When there are no rows to download in any of the linked downloaddatafxns the button will be hidden as there is nothing to download.
selection
parameter has different usage than DT::datatable selection
option.
See parameters usage section.
DT::datatable options editable
, width
and height
are not supported
This function is not called directly by consumers - it is accessed in
server.R using the same id provided in downloadableTableUI
:
downloadableTable(id, logger, filenameroot,
downloaddatafxns, tabledata, rownames, caption, selection)
Note: calling module server returns the reactive expression containing the currently selected rows in the display table.
downloadableTableUI
downloadFileButton
logViewerOutput
downloadFile
downloadFile_ValidateTypes
downloadFile_AvailableTypes
downloadablePlot
if (interactive()) {
library(shiny)
library(periscope2)
shinyApp(ui = fluidPage(fluidRow(column(width = 12,
downloadableTableUI("object_id1",
downloadtypes = c("csv", "tsv"),
hovertext = "Download the data here!",
contentHeight = "300px",
singleSelect = FALSE)))),
server = function(input, output) {
mydataRowIds <- function(){
rownames(head(mtcars))[c(2, 5)]
}
selectedrows <- downloadableTable(
id = "object_id1",
logger = "",
filenameroot = "mydownload1",
downloaddatafxns = list(csv = reactiveVal(mtcars), tsv = reactiveVal(mtcars)),
tabledata = reactiveVal(mtcars),
selection = mydataRowIds,
table_options = list(rownames = TRUE,
caption = "This is a great table!"))
observeEvent(selectedrows(), {
print(selectedrows())
})})
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.