-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from eodaGmbH/docs/shiny-vignette
Docs/shiny vignette
- Loading branch information
Showing
25 changed files
with
471 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ Imports: | |
glue, | ||
htmltools, | ||
htmlwidgets, | ||
jsonlite, | ||
purrr, | ||
readr, | ||
shiny | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# https://book.javascript-for-r.com/shiny-complete.html | ||
input_handler_data <- function(value, ...) { | ||
if (debug_mode()) { | ||
print("custom input handler data") | ||
} | ||
|
||
if (getOption("rtabulator.raw_data", FALSE)) { | ||
return(value) | ||
} | ||
|
||
data <- value$data | ||
try(data <- tabulator_data_as_df(value$data)) | ||
return(data) | ||
} | ||
|
||
# TODO: Not used at the moment | ||
input_handler_sheet_data <- function(value, ...) { | ||
if (debug_mode()) { | ||
print("custom input handler data") | ||
} | ||
|
||
if (getOption("rtabulator.raw_data", FALSE)) { | ||
return(value) | ||
} | ||
|
||
data <- value$data | ||
# try(data <- jsonlite::fromJSON(jsonlite::toJSON(value$data, auto_unbox = TRUE))) | ||
try(data <- sheet_data_to_matrix(data), silent = TRUE) | ||
return(data) | ||
} | ||
|
||
sheet_data_to_matrix <- function(data) { | ||
vec <- unlist(purrr::map(data, ~ as_vec(.x))) | ||
# try({vec <- as.numeric(vec)}) | ||
return(matrix(vec, nrow = length(data), byrow = TRUE)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
debug_mode <- function() { | ||
return(getOption("rtabulator.debug", FALSE)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.onLoad <- function(libname, pkgname) { | ||
# For devtools::load_all() we need to remove to handler if it is already registered | ||
try(shiny::removeInputHandler("rtabulator.data"), silent = FALSE) | ||
try(shiny::removeInputHandler("rtabulator.sheet_data"), silent = FALSE) | ||
|
||
try(shiny::registerInputHandler("rtabulator.data", input_handler_data)) | ||
try(shiny::registerInputHandler("rtabulator.sheet_data", input_handler_sheet_data)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
tabulator(iris) |> | ||
set_options_group_by("Species", group_start_open = FALSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
tabulator(iris) |> | ||
set_options_pagination(pagination_size_selector = c(10, 20, 50)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
library(shiny) | ||
library(rtabulator) | ||
|
||
ui <- fluidPage( | ||
titlePanel("Titanic Data Set"), | ||
tabulatorOutput("titanic"), | ||
actionButton("submit", "Submit data to R") | ||
) | ||
|
||
server <- function(input, output) { | ||
output$titanic <- renderTabulator({ | ||
tabulator(titanic(c("PassengerId", "Name", "Pclass", "Sex", "Fare", "Survived"))) |> | ||
set_formatter_progress("Fare") |> | ||
set_tooltip("Fare") |> | ||
set_formatter_tick_cross("Survived") |> | ||
set_formatter_star("Pclass", number_of_stars = 3) | ||
}) | ||
|
||
observeEvent(input$submit, { | ||
print(input$submit) | ||
tabulatorContext("titanic") |> | ||
trigger_get_data() | ||
}) | ||
|
||
observeEvent(input$titanic_get_data, { | ||
print(input$titanic_get_data) | ||
# print(head(tabulator_data_as_data_frame(input$titanic_get_data$data))) | ||
# print(list_to_data_frame(input$table_data$data)) | ||
}) | ||
} | ||
|
||
shinyApp(ui = ui, server = server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
library(shiny) | ||
library(rtabulator) | ||
|
||
ui <- fluidPage( | ||
titlePanel("Titanic Data Set"), | ||
tabulatorOutput("titanic") | ||
) | ||
|
||
server <- function(input, output) { | ||
output$titanic <- renderTabulator({ | ||
tabulator(titanic()) |> | ||
set_formatter_progress("Fare") |> | ||
set_tooltip("Fare") |> | ||
set_formatter_tick_cross("Survived") |> | ||
set_formatter_star("Pclass", number_of_stars = 3) | ||
}) | ||
} | ||
|
||
shinyApp(ui = ui, server = server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,70 @@ | ||
library(shiny) | ||
|
||
data_url <- "https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv" | ||
OUTPUT_ID <- "titanic" | ||
|
||
data <- titanic(c("PassengerId", "Pclass", "Survived", "Fare")) | ||
setup <- tabulator_options( | ||
selectable_rows = TRUE, | ||
edit_trigger_event = "focus" | ||
) | ||
|
||
ui <- fluidPage( | ||
titlePanel("Titanic Data"), | ||
tabulatorOutput("titanic") | ||
tabulatorOutput(OUTPUT_ID), | ||
actionButton("download", "Download"), | ||
actionButton("submit", "Submit data to R") | ||
) | ||
|
||
server <- function(input, output) { | ||
output$titanic <- renderTabulator({ | ||
tabulator(data_url, editable = TRUE) |> | ||
set_formatter_progress("Fare") |> | ||
tabulator(data, setup, editable = TRUE) |> | ||
set_header_filter("Pclass", "list") |> | ||
set_header_filter("Survived", "list") |> | ||
set_header_filter("Fare", "number", "<=", clearable = TRUE) |> | ||
set_options_pagination() |> | ||
set_formatter_money( | ||
"Fare", | ||
symbol = "\U00A3", symbol_after = FALSE, precision = 1, hoz_align = "right" | ||
) |> | ||
set_tooltip("Fare") |> | ||
set_formatter_tick_cross("Survived") |> | ||
set_formatter_star("Pclass", number_of_stars = 3) | ||
}) | ||
|
||
observeEvent(input$download, { | ||
tabulatorContext(OUTPUT_ID) |> | ||
trigger_download("csv") | ||
}) | ||
|
||
observeEvent(input$titanic_row_clicked, { | ||
print(input$titanic_row_clicked) | ||
}) | ||
|
||
observeEvent(input$titanic_rows_selected, { | ||
print("rows_selected") | ||
print(input$titanic_rows_selected) | ||
}) | ||
|
||
observeEvent(input$titanic_cell_edited, { | ||
print("cell_edited") | ||
print(input$titanic_cell_edited) | ||
}) | ||
|
||
observeEvent(input$titanic_data_filtered, { | ||
print("data_filtered") | ||
print(head(input$titanic_data_filtered)) | ||
}) | ||
|
||
observeEvent(input$submit, { | ||
print("Trigger get data") | ||
tabulatorContext(OUTPUT_ID) |> | ||
trigger_get_data() | ||
}) | ||
|
||
observeEvent(input$titanic_get_data, { | ||
print("Got data. Thanx!") | ||
print(head(input$titanic_get_data)) | ||
}) | ||
} | ||
|
||
shinyApp(ui = ui, server = server) |
Oops, something went wrong.