r - Revealing text in a shiny document -
in interactive document, possible use block of shiny code hide/reveal markdown?
a simple example of i'd is:
--- title: "example" output: html_document runtime: shiny --- $2+2$? ```{r reveal, echo=false} actionbutton("button", "reveal solution") #try (unsuccessfully) comment out rest of document renderui(html(ifelse(input$button, "", ("<!--")))) ``` answer $4$.
in real use case question , answer long , both involve shared randomly generated r variables.
here code should work you:
--- title: "example" output: html_document runtime: shiny --- $2+2$? ```{r reveal, echo=false} library(shiny) actionbutton("button", "reveal solution") #try (unsuccessfully) comment out rest of document rendertext({if(input$button == 0) {null }else{ print("the answer 4")}}) ```
if understood correctly wanted solution of 2 + 2
after pressing actionbutton
, therefore have used if...else...
statement saying if value of actionbutton == 0
, should return null
, else text: the answer 4
should printed.
Comments
Post a Comment