Table with selectable rows

1,503 views
Skip to first unread message

Kirill Savin

unread,
Jul 29, 2013, 2:03:50 PM7/29/13
to shiny-...@googlegroups.com
https://github.com/ksavin/SelectableRows
I wrote a binding for a reactive table to allow row selection and passing a row number to R (row number prints in console). I had an issue, but resolved it while making this example. Still have some questions.
1. Can I pass a value with renderUI so that specific row will be selected initially?
2. Is it possible to link *.js file with table generation? singleton(tags$head...) inside renderUI() adds an instance of a script to a page every time the table is updated.
3. The df2html function loops through value in data frame to generate tags. Does anyone knows better ways to make html tables from data frames?
Thanks.

Zhuo Jia Dai

unread,
Aug 9, 2013, 9:20:57 AM8/9/13
to shiny-...@googlegroups.com
This component is awesome! Thanks!

Kirill Savin

unread,
Aug 29, 2013, 7:22:50 AM8/29/13
to shiny-...@googlegroups.com
I assumed you need to highlight only one cell only, not an entire row. Updated the git with few more example tables.
https://github.com/ksavin/SelectableRows

On 28-Aug-13 09:36, Greg D wrote:
This is great! I don't have answers to your question, but do have a question... how could this be modified to get the row and column number?

Thanks.



Joe Cheng

unread,
Aug 30, 2013, 7:23:21 PM8/30/13
to shiny-...@googlegroups.com
I totally missed this, sorry. This looks great!

1) No, but you can access the values directly if you have df2html take the "session" object as an argument. You can access input values from session by doing session$input$testTbl4 or whatever.

2) Sorry, we don't have a great solution for this yet. The most robust yet easiest-to-forget option is to have a separate "initSelectableRows()" function that you force the user to call somewhere else in the UI. We'd like to make this better though.

3) I haven't really looked at it and it hasn't been touched in a long time, but maybe this? https://github.com/erikriverson/mutable


--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Kirill Savin

unread,
Aug 31, 2013, 5:33:33 AM8/31/13
to shiny-...@googlegroups.com
1. I was trying to figure out how to fire setValue event, but that will do just as well. Why didn't I think about it?!
Mutable looks interesting, I'll definitely check it out.
Thank you, Joe!

Paul Shannon

unread,
Oct 15, 2013, 11:44:09 PM10/15/13
to shiny-...@googlegroups.com
Hi Kirill (and Joe),

I was very happy to discover this reactive table. 

Due to my being an absolute shiny novice, however, I have been stalled for a few hours trying to add a feature.  Perhaps one of you can point me in the right direction?

What I wish to do is

   1) detect the cell that has been clicked (this works fine, of course)
   2) extract the original data from the underlying data.frame (also works)
   3) do some operations on that data (in my case, parse out a pubmed ID, and retrieve the related journal article abstract)
   4) display the text of the abstract in a textarea

In my experiments it would be completely adequate to skip step 3, and just display the data.frame[row,col] value in the  textarea. 

I can modify the contents of the target textarea, using some simple jquery added (inelegantly) to responsiveTable.js.
But back in R -- where I need to be, to have access to the data.frame, and to familiar code which can fetch the journal abstract, I do not know how to change the contents of the target textarea.  Perhaps some inline javascript could help do that?  Or is that too much a hack, and I need to define a reactive element that connects the responsiveTable event and the textarea?  If so, are their any examples of that you can suggest?

I suspect that if I had more completely absorbed the reactive programming idiom I would be able to figure out the answer.

Any guidance you can provided will be deeply appreciated!

Thanks,

 - Paul

ZJ

unread,
Oct 16, 2013, 12:08:06 AM10/16/13
to shiny-...@googlegroups.com
This post talks about update textarea.

https://groups.google.com/forum/m/#!topic/shiny-discuss/7Lk3-eGXQWI

I guess u just need to obtain the row and column. Can u post a gist if ur code?

I can try to modify it for u as an example.

Kirill Savin

unread,
Oct 16, 2013, 1:06:59 AM10/16/13
to shiny-...@googlegroups.com
It sounds like you simply need to put updateTextInput inside observe just like ZJ mentioned, no JavaScript needed. Would be something like
  observe({
    if (!is.null(input$myTable) && input$myTable != -1)
      updateTextInput(session, "myTextArea", value = retrieveAbstract(input$myTable))
  })

2 ZJ: I've posted an example table that returns row and column indexes to the git a while ago, but thanks!

Paul Shannon

unread,
Oct 16, 2013, 6:02:12 PM10/16/13
to Kirill Savin, Paul Shannon, shiny-...@googlegroups.com
This solved the problem perfectly. Thank you!

- Paul
> --
> You received this message because you are subscribed to a topic in the Google Groups "Shiny - Web Framework for R" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/shiny-discuss/ZaYYmFLHA6U/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to shiny-discus...@googlegroups.com.

Jan Stanstrup

unread,
May 24, 2014, 1:12:59 PM5/24/14
to shiny-...@googlegroups.com
Hi Kirill (and Joe),

This was exactly what I was looking for. However, I have made an app where I generate several tables dynamically and when I try to use this it will only work for the first table. I assume because the id is used to match the R variable?

What I would like to do is get the table (using the id or caption) and row returned.

Is that possible?
Reply all
Reply to author
Forward
0 new messages