2

I'm having a tough time getting ggvis and shiny to play nicely in an Rmarkdown-based application. I'm able to create the following ggvis figure with no problem even without using bind_shiny and ggvisOutput (as seen here):

---
title: "test"
runtime: shiny
output: html_document
---

```{r setup, include=FALSE}
require(ggvis)
knitr::opts_chunk$set(echo = TRUE)
```

```{r static}
inputPanel(
  sliderInput('n', 'n:', min = 10, max = 100, value = 50),
  actionButton('run', 'Run!')
)

data = data.frame(x = rnorm(50))

data %>%
  ggvis(~x) %>%
  layer_histograms()
```

However, I'm building dynamic reports to allow users to configure the input data and then re-execute by hitting a 'run' button, like this:

```{r config}
inputPanel(
  sliderInput('n', 'n:', min = 10, max = 100, value = 50),
  actionButton('run', 'Run!')
)

data = eventReactive(input$run, { data = data.frame(x = rnorm(input$n)) })

data %>%
  ggvis(~x) %>%
  layer_histograms()
```

When I try to run the document I get the nondescript error, Quitting from lines 26-36 (test.Rmd). Anyone know how to get this working?

UPDATE:

This almost works, but when I hit 'Run!' the ggvis plot renders in a separate browser window instead of in the document:

```{r config}
inputPanel(
  sliderInput('n', 'n:', min = 10, max = 100, value = 50),
  actionButton('run', 'Run!')
)

data = eventReactive(input$run, { data = data.frame(x = rnorm(input$n)) })

renderTable({summary(data())})

renderPlot({
  data() %>%
    ggvis(~x) %>%
    layer_histograms() %>%
    bind_shiny('plot')

})

ggvisOutput('plot')
```
4
  • does your data %>% ggvis(~x) %>%... need to infact be dependant on the reactive data(), so you would have data() %>% ggvis... ? Commented Feb 17, 2016 at 0:06
  • It shouldn't. ggvis can be passed "bare reactives" as shown here: stackoverflow.com/a/25060999/1574941 Commented Feb 17, 2016 at 0:19
  • ah ok, good to know. Commented Feb 17, 2016 at 0:25
  • 1
    change your renderPlot to reactive Commented Feb 17, 2016 at 0:58

1 Answer 1

1

The two questions you've linked to show you need the 'ggvis' code inside a reactive({, not a renderPlot({

This now works for me

---
title: "test"
runtime: shiny
output: html_document
---

```{r config}
library(ggvis)
inputPanel(
  sliderInput('n', 'n:', min = 10, max = 100, value = 50),
  actionButton('run', 'Run!')
)

data = eventReactive(input$run, { data = data.frame(x = rnorm(input$n)) })

renderTable({summary(data())})

reactive({
  data() %>%
    ggvis(~x) %>%
    layer_histograms() %>%
    bind_shiny('plot')

})

ggvisOutput('plot')
```
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.