Input values within table with DT package!

77 views
Skip to first unread message

Ivan Bezerra Allaman

unread,
Jul 2, 2015, 8:20:44 AM7/2/15
to shiny-...@googlegroups.com
Is possible to do something similar to http://datatables.net/examples/api/form.html with DT package?

Yihui Xie

unread,
Jul 2, 2015, 5:36:16 PM7/2/15
to Ivan Bezerra Allaman, shiny-discuss
Yes, it is. You can put HTML content in the table, and just remember
to use datatable(..., escape = FALSE). To submit the form, you need to
use the `callback` argument of datatable() to write a few lines of
JavaScript code.

This may give you some inspiration:
https://github.com/rstudio/DT/issues/93#issuecomment-111001538 and
please take some time to go through the full documentation of DT as
well: http://rstudio.github.io/DT/

Note, however, that currently you cannot edit the original data object
you passed to datatable() by editing the text inputs in the table.
That is a different problem: https://github.com/rstudio/DT/issues/28
You may need to elaborate on what you really want to do. "Something
similar" to the example you mentioned is definitely possible, but I
doubt that is what you want.

Regards,
Yihui

Ivan Bezerra Allaman

unread,
Jul 3, 2015, 11:13:02 AM7/3/15
to shiny-...@googlegroups.com, ivana...@gmail.com
"to write a few lines of JavaScript code" It is not something trivial to those who already know the language! The link https://github.com/rstudio/DT/issues/93#issuecomment-111001538 was an inspiration, but, I could not connect to the shinyInput column to another column in the same table. For example,

isolate({

newdata <- reactive({
data = data.frame(V1 = rnorm(10), V2 = rnorm(10))
n = dim(dados)[1]

qt = shinyInput(numericInput, n, 'qt', value=1)

values = shinyValues('qt',n) * rnorm(10)

newdata = data.frame(data, values)
newdata
})

 action_iba <- dataTableAjax(session, newdata(), rownames = TRUE)

              output$questions_iba <- DT::renderDataTable({
               datatable(
                         newdata(),
                         rownames = TRUE,
                         escape = FALSE,
                         options = list(
                                        ajax = list(url = action_iba),
                                        preDrawCallback = JS('function() { Shiny.unbindAll(this.api().table().node()); }'), 
                                        drawCallback =  JS('function() { Shiny.bindAll(this.api().table().node()); } ')
                                        )
                         #callback = JS('function() { Shiny.unbindAll(this.api().table().node()); }')
                         #function() { Shiny.bindAll(this.api().table().node()); }') 
                         )
              }) 
})

?????

Yihui Xie

unread,
Jul 3, 2015, 2:41:32 PM7/3/15
to Ivan Bezerra Allaman, shiny-discuss
I'm sorry, but I still didn't get what you were trying to do. What do
you mean by "connect"?

Regards,
Yihui


On Fri, Jul 3, 2015 at 10:13 AM, Ivan Bezerra Allaman
> --
> You received this message because you are subscribed to the Google Groups
> "Shiny - Web Framework for R" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to shiny-discus...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/shiny-discuss/f266937c-5370-46d2-88f7-bc2e9a87774f%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Ivan Bezerra Allaman

unread,
Jul 3, 2015, 3:27:07 PM7/3/15
to shiny-...@googlegroups.com, ivana...@gmail.com
Sorry! Following an example of my idea!

library(shiny)
library(DT)

shinyApp(
         ui = fluidPage(
                        helpText(h2("It pretends that these commands is the first column of the table below. (COLUMN 1)")),
                        numericInput('a','',value=1),
                        numericInput('b','',value=1),
                        DT::dataTableOutput('dados'),
                        helpText(h1("NOTE: The column2 is a product between column1 and a any vector"))
                        ),

         server = function(input, output) {
          # create a character vector of shiny inputs

          dados <- reactive({

           dad <- data.frame(COLUMN2 = c(.5,2) * c(input$a, input$b))

          })

          output$dados <- renderDataTable({dados()})

         }
         ) 

Thank you for the patience!
Reply all
Reply to author
Forward
0 new messages