Expand/collapse wellPanel on click. Possible?

2,164 views
Skip to first unread message

Matthew Leonawicz

unread,
Jun 18, 2013, 4:28:25 PM6/18/13
to shiny-...@googlegroups.com
Is it possible to use Javascript with Shiny to expand and collapse individual wellPanels in the sidebar upon a button click? I have tried various manifestations of mixing some canned javascript with shiny apps but no luck yet.
For example, things like:

sidebarPanel(
tags$head(
tags$script(type="text/javascript", src="http://code.jquery.com/jquery-1.9.1.js") #### or: src="www/js/jquery-1.9.1.js"
                ....
        ),
        HTML("<button>Expand/Collapse</button>"),
        div(id='wpDiv1',class='wpDiv',
        wellPanel(...
                #### various input controls
                ...)
        ),...

and somewhere, but I don't know where, something like:
<script>
$("button").click(function () {
$("wpDiv").slideToggle("slow");
});
</script>

which I'll call button1.html and for the time being I have included in the sidebarPanel call as includeHTML("www/html/button1.html")

Of course, none of this works, except for the simple HTML("<button>Expand/Collapse</button>") call which does make a non-functional button. I am guessing the tags$script thing is not right. I have tried various combination of tags, div, HTML, includeHTML. I have tried the shinyIncubator actionButton instead of the generic button. I have tried different placements in the ui.R script. But I don't actually even know if this is something that is possible to do in the first place. I would like a wellPanel that begins short, only revealing say, a button, which can be clicked to expand the wellPanel to show a larger vertical list of inputs (and shrink back as well). Can this be done?

Thanks,
Matt


Joe Cheng

unread,
Jun 18, 2013, 4:58:21 PM6/18/13
to shiny-...@googlegroups.com
I think a checkbox would be better. You can combine a checkbox with conditionalPanel pretty easily.

checkboxInput('showPanel1', 'Show panel', FALSE),
conditionalPanel(condition = 'input.showPanel1',
  wellPanel( ... )
)




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

Matthew Leonawicz

unread,
Jun 18, 2013, 7:04:23 PM6/18/13
to shiny-...@googlegroups.com
That is much easier. Thank you!

Matt

Bernard bakala

unread,
Jul 5, 2021, 8:51:19 PM7/5/21
to Shiny - Web Framework for R
Wow! this was helpful. 
Thanks Joe

Reply all
Reply to author
Forward
0 new messages