From 4bf32c36e7b9e5234e43611b504baafe6ae3c6ed Mon Sep 17 00:00:00 2001 From: Stefan Kuethe Date: Tue, 17 Sep 2024 14:41:33 +0200 Subject: [PATCH] Fix pkgdown site --- _pkgdown.yml | 2 +- vignettes/articles/shiny.Rmd | 66 +++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/_pkgdown.yml b/_pkgdown.yml index ea3ba67..b11a6ff 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -41,7 +41,7 @@ reference: - delete_selected_rows - trigger_download - trigger_get_data - - trigger_get_spreadsheet_data + - trigger_get_sheet_data - undo - redo diff --git a/vignettes/articles/shiny.Rmd b/vignettes/articles/shiny.Rmd index b3a9797..57e98f0 100644 --- a/vignettes/articles/shiny.Rmd +++ b/vignettes/articles/shiny.Rmd @@ -14,7 +14,7 @@ library(shiny) library(rtabulator) ``` -## Basic application +## Basic Usage Use `tabulatorOutput()` in the UI and `renderTabulator()` in the server part of your Shiny application: @@ -36,3 +36,67 @@ server <- function(input, output) { shinyApp(ui = ui, server = server) ``` + +## Interactions + +**Triggers** + +- `trigger_download()` +- `trigger_get_data()` +- `trigger_get_sheet_data()` + +**Events** + +- `{OUTPUT_ID}_row_clicked` +- `{OUTPUT_ID}_rows_selected` +- `{OUTPUT_ID}_data_filtered` +- `{OUTPUT_ID}_get_data` +- `{OUTPUT_ID}_get_sheet_data` +- ... + +```{r, eval=FALSE} +library(shiny) + +OUTPUT_ID <- "titanic" + +data <- titanic(c("PassengerId", "Pclass", "Survived", "Fare")) +setup <- tabulator_options(selectable_rows = TRUE) + +ui <- fluidPage( + titlePanel("Titanic Data"), + tabulatorOutput(OUTPUT_ID), + actionButton("submit", "Submit data to R") +) + +server <- function(input, output) { + output$titanic <- renderTabulator({ + tabulator(data, setup, editable = TRUE) |> + set_options_pagination() |> + set_formatter_progress("Fare") |> + set_tooltip("Fare") |> + set_formatter_tick_cross("Survived") |> + set_formatter_star("Pclass", number_of_stars = 3) + }) + + observeEvent(input$titanic_row_clicked, { + print(input$titanic_row_clicked) + }) + + observeEvent(input$titanic_rows_selected, { + print(input$titanic_rows_selected) + }) + + 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) +```