Pattern for actionlinks

1,529 views
Skip to first unread message

Alex Brown

unread,
Jun 7, 2013, 11:12:11 AM6/7/13
to shiny-...@googlegroups.com
Here's what I want to do - 

  Have clickable elements such as links and table rows.

  Each click should communicate with shiny server to perform an action.

  Actionbutton almost does this, but is hard to generalize to clicking table rows

  Working example.

  tags$a(href="#", class="action-button shiny-bound-input", id="load_url", "Load URL")),
 
  In addition when I have multiple things that should link to the same input "clicked_url" I can't get
  that data passed to the shiny server.

  Perhaps actionButton could take a data value, and return a pair of "count" and "value" - or just "value" (although that
  might make links unclickable if the last selected value is the current one.

  tags$a(href="#", class="action-button shiny-bound-input", id="load_url", "Load URL")),

  Any ideas?

-Alex

Joe Cheng

unread,
Jun 7, 2013, 12:09:03 PM6/7/13
to shiny-...@googlegroups.com
The "count/value" pair approach is exactly what I did in a recent Shiny app and it worked great.

Regarding multiple things linking to the same input value, I think we need the idea of input values that aren't tied to any one HTML element, you just use JavaScript to set them; then you can point to them from all over. Same for outputs, actually.



-Alex

--
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.
 
 

Jeff Wenzinger

unread,
Sep 4, 2014, 10:08:58 PM9/4/14
to shiny-...@googlegroups.com
Hi gents,

I am trying to create a user flow from one tab to another using action links in a data table.  I'm pretty close but having some trouble because I want to generate a dynamic number of action links and have the links switch the active tab but update selectize input with a unique value.

Here is my shiny code.

ui.R
actionLink('action5463', label = 'Go to Campaign', icon = NULL),

server.R
observe({
  if(input$action5463 == 0) return(NULL)
  updateTabsetPanel(session,'tab',selected = 'Campaign')
  updateSelectizeInput(session,'campaign', selected = 'Campaign 5463')

html generated by shiny:
<a id="action5463" href="#" class="action-button shiny-bound-input">Go to Campaign</a>

This works, but it is a static link that can't place in a data table, and can't generate a variable number of them (I successfully did the for external links by concatenating "<a href=http://blah.com/,' campaigns$campaign_id, '>link</a>" with a vector of campaign ids..  

Out of curiosity, I tried creating the following as a separate action link in a data table, but the link did not appear to pass anything to the server, as in Alex's comment.
<a id="action5463" href="#" class="action-button shiny-bound-input">test</a>

I am trying to troubleshoot this issue, as well as determine feasibility.  Is this even possible?

Thanks,
Jeff

Fan Li

unread,
Jan 28, 2015, 8:24:54 AM1/28/15
to shiny-...@googlegroups.com
To follow up on Jeff's last comment, is there a solution to add an action link in a data table?

For example, if I have "<a id="a1" href="#" class="action-button shiny-bound-input">Link</a>" as an entry in a data table, the hyperlink will render correctly but there is no action event.

ui <- shinyUI(fluidPage(
  dataTableOutput("dt"),
  #HTML("<a id='a1' href='#' class='action-button shiny-bound-input'>Link</a>"),  # This link works
  textOutput("txt")
))

server <- function(input, output) {
  output$dt <- renderDataTable(
    data.frame(Name="a1", Link="<a id='a1' href='#' class='action-button shiny-bound-input'>Link</a>"),
    escape = FALSE, options = list(paging = FALSE, searching = FALSE, searchable = FALSE)
  )
  output$txt <- eventReactive(input$a1, "actionLink is working")
}

shinyApp(ui = ui, server = server)

Joe Cheng

unread,
Jan 28, 2015, 3:26:52 PM1/28/15
to Fan Li, shiny-...@googlegroups.com
I believe you'll have to use some custom JavaScript for this. Here's what I did for the superzip example:

Note that the superzip example was written for an older version of Shiny, so the renderDataTable call doesn't include the necessary "escape" argument that you would need for Shiny 0.11.

Reply all
Reply to author
Forward
0 new messages