Skip to content

Commit

Permalink
Add default spreadsheet options
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Sep 12, 2024
1 parent 08bd119 commit 5be88c2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R/js_dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SHEETJS_VERSION <- "0.20.1"
# Needed to support xlsx downloads
sheetjs_dependency <- htmltools::htmlDependency(
name = "sheetjs",
version =SHEETJS_VERSION,
version = SHEETJS_VERSION,
src = list(
href = glue::glue("https://cdn.sheetjs.com/xlsx-{SHEETJS_VERSION}/package/dist/")
),
Expand Down
5 changes: 4 additions & 1 deletion R/tabulator.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ tabulator <- function(
...) {
if (is.null(options)) options <- list()

if (class(data) == "character") {
if (is.character(data)) {
data <- readr::read_csv(data, show_col_types = FALSE)
}

# TODO: Use Pipe, but then we need to set required R Version to > 4.1
options <- utils::modifyList(options, list(...))
options <- keys_to_camel_case(compact(options))
if (isTRUE(options$spreadsheet)) {
# ...
options <- utils::modifyList(default_spreadsheet_options, options)
} else {
data <- fix_colnames(data)
if (getOption("rtabulator.auto_columns", TRUE) && is.null(options$columns)) {
Expand Down
14 changes: 12 additions & 2 deletions R/tabulator_options.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Table Options
#' Tabulator Setup Options
#' @param height (character) The height of the table in px.
#' @param history (bool): description
#' @param colummns (list): description
Expand Down Expand Up @@ -45,7 +45,7 @@ tabulator_options <- function(
spreadsheet = FALSE,
spreadsheet_rows = NULL,
spreadsheet_columns = NULL,
spreadsheet_column_definition = list(editor = "input"),
spreadsheet_column_definition = NULL,
spreadsheet_sheets = NULL,
spreadsheet_sheet_tabs = NULL,
...) {
Expand All @@ -54,3 +54,13 @@ tabulator_options <- function(
params$add_row_pos <- match.arg(add_row_pos)
return(c(params, list(...)))
}

default_spreadsheet_options <- list(
row_header = list(
field = "_id",
hozAlign = "center",
headerSort = FALSE,
frozen = TRUE
),
spreadsheet_column_definition = list(editor = "input")
)
3 changes: 1 addition & 2 deletions examples/shiny/titanic/app.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
library(shiny)

data_url <- "https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv"
titanic_tibble <- readr::read_csv(data_url)

ui <- fluidPage(
titlePanel("Titanic Data"),
Expand All @@ -10,7 +9,7 @@ ui <- fluidPage(

server <- function(input, output) {
output$titanic <- renderTabulator({
tabulator(titanic_tibble, editable = TRUE) |>
tabulator(data_url, editable = TRUE) |>
set_progress_formatter("Fare") |>
set_tick_cross_formatter("Survived") |>
set_star_formatter("Pclass", number_of_stars = 3)
Expand Down

0 comments on commit 5be88c2

Please sign in to comment.