Display a table in a window
Usage
show_data(
data,
title = NULL,
options = NULL,
show_classes = TRUE,
type = c("popup", "modal", "winbox"),
width = "65%",
...
)
Arguments
- data
a data object (either a
matrix
or adata.frame
).- title
Title to be displayed in window.
- options
Arguments passed to
toastui::datagrid()
.- show_classes
Show variables classes under variables names in table header.
- type
Display table in a pop-up with
shinyWidgets::show_alert()
, in modal window withshiny::showModal()
or in a WinBox window withshinyWidgets::WinBox()
.- width
Width of the window, only used if
type = "popup"
ortype = "winbox"
.- ...
Additional options, such as
wbOptions = wbOptions()
orwbControls = wbControls()
.
Note
If you use type = "winbox"
, you'll need to use shinyWidgets::html_dependency_winbox()
somewhere in your UI.
Examples
library(shiny)
library(datamods)
ui <- fluidPage(
theme = bslib::bs_theme(version = 5L),
shinyWidgets::html_dependency_winbox(),
actionButton(
inputId = "show1",
label = "Show data in popup",
icon = icon("eye")
),
actionButton(
inputId = "show2",
label = "Show data in modal",
icon = icon("eye")
),
actionButton(
inputId = "show3",
label = "Show data without classes",
icon = icon("eye")
),
actionButton(
inputId = "show4",
label = "Show data in Winbox",
icon = icon("eye")
)
)
server <- function(input, output, session) {
observeEvent(input$show1, {
show_data(MASS::Cars93, title = "MASS::Cars93 dataset", type = "popup")
})
observeEvent(input$show2, {
show_data(MASS::Cars93, title = "MASS::Cars93 dataset", type = "modal")
})
observeEvent(input$show3, {
show_data(
data = MASS::Cars93,
title = "MASS::Cars93 dataset",
show_classes = FALSE,
options = list(pagination = 10),
type = "modal"
)
})
observeEvent(input$show4, {
show_data(
MASS::Cars93,
title = "MASS::Cars93 dataset",
type = "winbox",
wbOptions = shinyWidgets::wbOptions(background = "forestgreen")
)
})
}
if (interactive())
shinyApp(ui, server)