Use action button to control output display

2,093 views
Skip to first unread message

Vicky Yang

unread,
Jan 4, 2013, 2:20:32 PM1/4/13
to shiny-...@googlegroups.com
Dear shiny list, 

I'd like to see if some could give me some ideas on how to get this done.

On the page, there are  2 checkboxes, say "A" and "B" and a "go" actionButton. I'd like to show: (1) "thing1" if "A" checked and "go" clicked; (2) "thing2" if "B" checked and "go" clicked; (3) nothing or no updates if "go" not clicked. What puzzels me is how to evaluate "go" button has been clicked in the mainPanel() of "ui.R".  

Assuming I could only use actionButton (not submitButton), how could I get this done? Or maybe the way I design my page is too cumbersome? 

Any inputs are welcome. Thank you in advance!

-vicky

Joe Cheng

unread,
Jan 4, 2013, 4:30:19 PM1/4/13
to shiny-...@googlegroups.com

Vicky Yang

unread,
Jan 14, 2013, 7:58:04 PM1/14/13
to shiny-...@googlegroups.com
Thanks for pointing out the new feature. I might be doing something wrong or not choosing the best way to implement my idea.

I am still struggling with control outputs based on input values. I want to display (1) "Thing1" when "A" checked and "go" clicked;(2) "Thing2" when "B" checked and "go" clicked; (3) show nothing if none of "A" and "B" checked; (4) "no update" if "go" was not clicked on. 

Here is a simplified version of my codes, please forgive me on my conditionalPanel, it's very likely I wrote the wrong conditions with my barely nothing js knowledge.  

ui.R
library(shiny)
library('shinyIncubator')

# Define UI for dataset viewer application
shinyUI(pageWithSidebar(
  
  # Application title
  headerPanel("Testing"),
   
  # Sidebar with controls to create filters or generate query
  sidebarPanel(
    
    checkboxGroupInput("foo", "Choose", choices = list("A"=1, "B"=2), selected = 1)
    , actionButton('ab','Go')
  ),
  
  mainPanel(
    conditionalPanel(
      condition = "input.ab > 0 && ['A'].indexOf(input.foo) < 0"
      , h4("Thing1")), 

    conditionalPanel(
      condition = "input.ab > 0 && ['B'].indexOf(input.foo) < 0"
      , h4("Thing2"))     
  )
))



server.R
library(shiny)
library('shinyIncubator')

shinyServer(function(input, output) {
 
})

Vincent

unread,
Jan 16, 2013, 4:48:55 AM1/16/13
to shiny-...@googlegroups.com
Your question seemed related to something I would like to be able to do in Shiny so I played around with your code for a while (question https://groups.google.com/forum/?fromgroups=#!topic/shiny-discuss/rgW0LYbY6QE). I tried a number of options. They sort-of work but once the button has been pushed 1-time there is no 'waiting' for another press - something will be printed. I assume option 2 is closest to what you are looking for. In the 4th option I tried to use a reactive in server.R but was not successful. If you figure out how to do this please let the list know.


To run the gist use:

shiny::runGist('4545922')

Vicky Yang

unread,
Jan 16, 2013, 6:32:39 PM1/16/13
to shiny-...@googlegroups.com
Vincent, thanks for playing with the code. The problem is how to control that "waiting" for another press. I am still struggling with finding a way to log that click and expressing it properly in conditionalPanel's "condition". :(

Joe Cheng

unread,
Jan 16, 2013, 6:37:11 PM1/16/13
to shiny-...@googlegroups.com
Could you use submitButton instead of actionButton? The main problem with submitButton is that it holds up evaluation of ALL the other inputs on the page, you can't specify that it should only apply to one particular group of inputs. If that's not a problem for you then it sounds like submitButton is what you're looking for.


--
 
 

Vicky Yang

unread,
Jan 16, 2013, 6:46:19 PM1/16/13
to shiny-...@googlegroups.com
This is a simplified version of what I am trying to accomplish. The rest of the implementation requires this button to be an actionButton unfortunately. 

--
 
 

Reply all
Reply to author
Forward
0 new messages