How can I hide reactive code that I need for ggvis from being displayed in rMarkdown

19 views
Skip to first unread message

Andy Clark

unread,
Sep 15, 2014, 11:38:10 AM9/15/14
to shinyap...@googlegroups.com
This a repeat of a question in the shiny discussion group but probably makes more sense here

I want to hide my code but echo=FALSE does not work for a reactive

```{r, echo = FALSE, message=FALSE}
library(ggplot2)
library(ggvis)
library(dplyr)

selectInput("category", "Choose Dataset:", c("mpg", "disp", "qsec"))

testCode <- max(mtcars$mpg)

# ggvis with dynamically changing columns
reactive({
  if (!is.null(input$category))
    col <- input$category
  else
    col <- "mpg"
  
  mtcars %>% ggvis(~mpg, ~disp)
  
}) %>% bind_shiny('foo')

ggvisOutput('foo')
```

The selectInput and ggvis chart show as required and the testCode line is hidden but I get 

## reactive({
##     if (!is.null(input$category)) 
##         col <- input$category
##     else col <- "mpg"
##     mtcars %>% ggvis(~mpg, ~disp)
## })

on the page , which is not desired

TIA

Joe Cheng

unread,
Sep 15, 2014, 11:53:33 AM9/15/14
to Andy Clark, shinyap...@googlegroups.com, Winston Chang
(cc Winston)

I think the problem here is that you have the ggvis() call inside the reactive and the bind_shiny() call outside of it. I think if you either move the ggvis call to be after the reactive, OR change "reactive" to "observe" and move bind_shiny('foo') to the inside, then the problem should be fixed.

--
You received this message because you are subscribed to the Google Groups "ShinyApps Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shinyapps-use...@googlegroups.com.
To post to this group, send email to shinyap...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shinyapps-users/180f6097-cdc8-4fb7-8d5b-e1207a690d6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andy Clark

unread,
Sep 15, 2014, 1:39:28 PM9/15/14
to shinyap...@googlegroups.com, ag...@rogers.com, win...@rstudio.com
I went the observe route and that seems to work fine. Thanks a lot. Now I can hide my ugly code
Reply all
Reply to author
Forward
0 new messages