Skip to content

Instantly share code, notes, and snippets.

@ijlyttle
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save ijlyttle/a37bea7952f1ac9f12ba to your computer and use it in GitHub Desktop.

Select an option

Save ijlyttle/a37bea7952f1ac9f12ba to your computer and use it in GitHub Desktop.
Issues with ggvis, shiny, and rmarkdown
> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggvis_0.3.0.99 shiny_0.10.1.9000 devtools_1.5
loaded via a namespace (and not attached):
[1] assertthat_0.1 digest_0.6.4 dplyr_0.2 evaluate_0.5.5 formatR_0.10 htmltools_0.2.4
[7] httpuv_1.3.0 httr_0.3 knitr_1.6.3 magrittr_1.0.1 memoise_0.2.1 parallel_3.1.0
[13] Rcpp_0.11.2 RCurl_1.95-4.1 RJSONIO_1.2-0.2 rmarkdown_0.2.50 stringr_0.6.2 tools_3.1.0
[19] whisker_0.3-2 xtable_1.7-3 yaml_2.1.11
---
title: "shiny, rmarkdown, ggvis: fluidRow issue"
author: "Ian Lyttle and Alex Shum"
runtime: shiny
output:
html_document:
theme: united
---
In this case, run from the command line, both apps render legibly, but ggvis does not appear to wish to conform to the horizontal dimension of the column it is put into.
Run in subApp mode, ggvis respects the horizontal dimension, but does something funny for the vertical dimension.
```{r}
library(ggvis)
library(shiny)
```
```{r}
app_test2 <- shinyApp(
ui = fluidPage(
fluidRow(
column(3, wellPanel()),
column(3, wellPanel(ggvisOutput("cocaine1"))),
column(3, wellPanel())
),
fluidRow(
column(3, wellPanel()),
column(3, wellPanel(ggvisOutput("cocaine2"))),
column(3, wellPanel())
)
),
server = function(input, output, session){
cocaine %>%
ggvis(x = ~weight, y = ~price) %>%
layer_points() %>%
set_options(width = 250, height = 250) %>%
bind_shiny("cocaine1")
cocaine %>%
ggvis(x = ~weight, y = ~potency) %>%
layer_points() %>%
set_options(width = 250, height = 250) %>%
bind_shiny("cocaine2")
},
options = list(height = "500")
)
app_test2
```
```{r}
app_test3 <- shinyApp(
ui = fluidPage(
fluidRow(
column(3, wellPanel()),
column(6, wellPanel(ggvisOutput("cocaine1"))),
column(3, wellPanel())
),
fluidRow(
column(3, wellPanel()),
column(6, wellPanel(ggvisOutput("cocaine2"))),
column(3, wellPanel())
)
),
server = function(input, output, session){
cocaine %>%
ggvis(x = ~weight, y = ~price) %>%
layer_points() %>%
set_options(width = 250, height = 250) %>%
bind_shiny("cocaine1")
cocaine %>%
ggvis(x = ~weight, y = ~potency) %>%
layer_points() %>%
set_options(width = 250, height = 250) %>%
bind_shiny("cocaine2")
},
options = list(height = "500")
)
app_test3
```
---
title: "shiny, rmarkdown, ggvis: navbarPage issue"
author: "Ian Lyttle and Alex Shum"
runtime: shiny
output:
html_document:
theme: united
---
This is a minimal (if not small) example of something that works as a shinyApp run from the command-line, but does not work as an embedded app.
Rendered within rmarkdown, it appears that the ggvis in the "default" tabPanel works well, but that the other(s) don't.
Run as a command-line app, the plots both render identically, but they are now not respecting the size of the column I have put them in.
This may be a different issue, but it would be great to be able to tell shiny (or ggvis) that I would like the plot to fill the available horizontal space provided by a column (or, perhaps, some specified percentage), and to keep a certain (specified) aspect ratio.
```{r echo = FALSE}
library(ggvis)
app_test <- shinyApp(
ui = navbarPage(
"menubar test",
tabPanel(
"Works",
fluidRow(
column(6, ggvisOutput("cocaine1")),
column(6, wellPanel())
)
),
tabPanel(
"Does not work",
fluidRow(
column(6, ggvisOutput("cocaine2")),
column(6, wellPanel())
)
)
),
server = function(input, output, session){
cocaine %>%
ggvis(
x = ~weight, y = ~price, fill = ~potency,
fillOpacity := 0.5) %>%
layer_points() %>%
bind_shiny("cocaine1")
cocaine %>%
ggvis(
x = ~weight, y = ~price, fill = ~potency,
fillOpacity := 0.5) %>%
layer_points() %>%
bind_shiny("cocaine2")
}
)
app_test
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment