how hide rendered shiny
output? specifically, have figures/tables generated shiny
, have button, when clicked should hide figures/tables, , when clicked again should show them.
this have far (below), , works somewhat, it's supposed hide renderplot
output, there big blank space in document trying make go away.
it should possible copy , paste code rstudio , hit run document (it's rmarkdown shiny runtime).
--- runtime: shiny --- ```{r, echo=f} actionbutton("hide", "hide") dat <- data.frame(a=1:10, b=rexp(10, 1/10), c=letters[sample(1:24, 10)]) rendertable({ if (input$hide %% 2 == 1) dat }) ``` lodi dodi ```{r, echo=f} renderplot({ if (input$hide %% 2 == 1) plot(b ~ a, data=dat) }) ``` text separated blank space, shouldn't
you can use shinyjs
package hide elements hide()
function (or use toggle()
function alternate between hiding , showing). disclaimer: wrote package.
i've never used in rmarkdown before, i'm going show how use in normal shiny app , use shinyapp()
function include full shiny app inside rmarkdown. can read here how include shiny apps inside rmarkdown doc.
--- runtime: shiny --- ```{r, echo=f} suppresspackagestartupmessages( library(shinyjs) ) dat <- data.frame(a=1:10, b=rexp(10, 1/10), c=letters[sample(1:24, 10)]) shinyapp( ui = fluidpage( useshinyjs(), actionbutton("hide", "hide"), p("text above plot"), plotoutput("plot"), p("text below plot") ), server = function(input, output, session) { output$plot <- renderplot({ plot(b ~ a, data=dat) }) observeevent(input$hide, { hide("plot") # toggle("plot") if want alternate between hiding , showing }) }, options = list(height = 700) ) ```
in order able use hide, had to:
- install , load
shinyjs
- add call
useshinyjs()
in ui - call
hide
ortoggle
on element want hide/show
i hope helps
Comments
Post a Comment