Giter VIP home page Giter VIP logo

Comments (1)

ThomasSiegmund avatar ThomasSiegmund commented on June 26, 2024

Hi,

thanks @saxodel for the nice comments.

I can't say that I have understood completely what's going on. I've fixed one bug in the D3TableFilter javascript preventing the select input from working in a module. Then I modified your example sligthly (see below.). In this version the observer in the server function works, but the reactive in the module doesn't work, even if it is listening to the same input. I guess I need to dig a bit deeper in shiny modules...

Best

# d3tabModule.R

d3tabUI <- function(id) {
  ns <- NS(id)
  
  tagList(
    column(d3tfOutput(ns('mtcars')), width = 8),
    column(tableOutput(ns("mtcarsSelect")), width = 4)
  )
}

d3tab <- function(input, output, session, data) {
  
  ns <- session$ns

  output$mtcars <- renderD3tf({
    
    tableProps <- list(
      btn_reset = TRUE,
      rows_counter = TRUE,  
      rows_counter_text = "Rows: ",
      sort = TRUE,
      on_keyup = TRUE,  
      on_keyup_delay = 800,
      sort_config = list(
        sort_types = c("Number", "Number")
      ),
      filters_row_index = 1,
      rows_always_visible = list(nrow(mtcars) + 2),
      col_operation = list( 
        id = list("frow_0_fcol_1_tbl_mtcars","frow_0_fcol_2_tbl_mtcars"),    
        col = list(1,2),    
        operation = list("mean","mean"),
        write_method = list("innerhtml",'innerhtml'),  
        exclude_row = list(nrow(mtcars) + 2),  
        decimal_precision = list(1, 1)
      )
    );
    
    footData <- data.frame(Rownames = "Mean", mpg = 0, cyl = 0);
    
    d3tf(mtcars[ , 1:2],
         enableTf = TRUE,
         tableProps = tableProps,
         showRowNames = TRUE, 
         selectableRows = "multi",
         selectableRowsClass = "info",
         tableStyle = "table table-bordered table-condensed",
         rowStyles = c(rep("", 7), rep("info", 7)),
         filterInput = TRUE,
         footData = footData,
         height = 500);
  })
  
  mtcarsInput <- reactive({
     inputID <- ns("mtcars_select")
     print("inputID in mtcarsInput ")
     print(inputID)
     print(input[[inputID]])
     if(is.null(input[[inputID]])) return(NULL)
     return(input[[inputID]]) 
    })
  
  # for a output object "mtcars" tableFilter generates an input
  # "mtcars_edit". 
  output$mtcarsSelect <- renderTable({
     if (is.null(mtcarsInput())) return(invisible());
     mtcarsInput()[ , 1:2];
  })
}
# app.R

library(shiny)
library(htmlwidgets)
library(D3TableFilter)

source("d3tabModule.R")


ui <- fluidPage(
  d3tabUI("d3tab")
)


server <- function(input, output) {
  
  observe({
    print("d3tab-mtcars_select in server")
    print(input[['d3tab-mtcars_select']])
  })
  
  callModule(d3tab, "d3tab", data(mtcars))
}


shinyApp(ui = ui, server = server)

from d3tablefilter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.