Quantcast
Channel: R Shiny and Tabulator - Stack Overflow
Viewing all articles
Browse latest Browse all 3

R Shiny and Tabulator

$
0
0

I've searched for "r shiny tabulator" and expected more results than zero. Is embedding a Tabulator in R Shiny apps at all possible? Can Tabulator events be sent back to R?

I've created a sample tabulator. The test app below contains all the jQuery references we use in another app but I'm not sure if they are required in R.

Where to take it from there to initialize and show the two rows of sample data in tabulatorDiv?

library(shiny)library(shinyjs)tabulatorClass <- "class AIClass {    doLoad() {        const sampleData = [            { AI: 'Substance2', AIGroup: 'GroupA', Volume: 1.23, Price: 4.56, Included: true },            { AI: 'Substance1', AIGroup: 'GroupB', Volume: 3.21, Price: 6.54, Included: true },        ];        this.aiTableCopy = structuredClone(sampleData);        this.aiTableCopy.forEach(a => a.newRow = false);        const aiTableCopyTemp = structuredClone(this.aiTableCopy);        if (!this.aiTable) {            this.aiTable = new Tabulator('#tabulatorDiv', {                columns: [                    { title: 'AI', field: 'AI', width: 100 },                    { title: 'AIGroup', field: 'AIGroup', width: 100 },                    { title: 'Volume', field: 'Volume', width: 100 },                    { title: 'Price', field: 'Price', width: 100 },                    { title: 'Included', field: 'Included', width: 75 }                ],                initialSort: [{ column: 'AI', dir: 'asc' }],                data: aiTableCopyTemp            });            this.aiTable.on('cellEdited', function (cell) {                cell._cell.row.data.newRow = false;                myClass.doSave();            });            this.aiTable.on('tableBuilt', function () {            });        }        else {            this.aiTable.replaceData(aiTableCopyTemp);        }    }    doSave() {        // how to do this in R Shiny will be the subject of another question    }}const myClass = new AIClass();"ui <-   htmltools::tagList(    shinyjs::useShinyjs(),    htmltools::tags$head(      htmltools::tags$script(src = "https://code.jquery.com/jquery-1.11.3.min.js"), # is this needed?      htmltools::tags$script(src = "https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"), # is this needed?      htmltools::tags$link(rel = "stylesheet", type = "text/css", href = "https://unpkg.com/tabulator-tables@5.3.4/dist/css/tabulator.min.css"),      htmltools::tags$link(rel = "stylesheet", type = "text/css", href = "https://cdnjs.cloudflare.com/ajax/libs/tabulator/5.3.4/css/tabulator_bootstrap5.min.css"),      htmltools::tags$script(src = "https://unpkg.com/tabulator-tables@5.3.4/dist/js/tabulator.min.js"),      htmltools::tags$script(tabulatorClass)    ),    fluidPage(      div(id = "tabulatorDiv")    ))server <- function(input, output, session) {  # how to initialize and show Tabulator?  # myClass.doLoad();}shinyApp(ui, server)

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images