Last active
August 30, 2017 14:27
-
-
Save ashraaghav/1d02dd8d1d519f3703d97bf7de57192c to your computer and use it in GitHub Desktop.
This is a sample Rmarkdown-Shiny file that crashes every second time a ggplot/lattice object is rendered, without throwing an error. This problem seems to happen only when a package that uses java is imported. (RJava does not cause any problems)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "TestMarkdownShiny" | |
author: "Ashwin Raaghav" | |
date: "30 August 2017" | |
output: html_document | |
runtime: shiny | |
--- | |
This R Markdown document is made to test the functioning of **renderplot** rendering a **ggplot** when a library that uses ***rJava*** is imported into the session. | |
The second time the ggplot plot is rendered, it crashes the document itself, without throwing any error. | |
```{r version} | |
version | |
``` | |
## Shiny - Ggplot2 - Rjava test | |
```{r Shiny renderplot Ggplot2 Rjava test, echo=FALSE, results='asis', warning=FALSE, error=FALSE} | |
## rJava based libraries cause a problem. | |
library(openNLP) | |
library(wordnet) | |
library(openNLPmodels.en) | |
library(RWeka) | |
library(Rdrools) | |
## Interestingly enough, rJava does not cause a problem.... | |
# library(rJava) | |
library(shiny) | |
library(ggplot2) | |
library(lattice) | |
renderText("Now we see how it works...") | |
inputPanel( | |
actionButton('submit', 'Click twice to crash') | |
) | |
uiOutput('ggOut') | |
observeEvent(input$submit, { | |
df <- data.frame('words' = LETTERS[1:20], 'number' = round(runif(20, 0, 100)), stringsAsFactors = FALSE) | |
output$ggOut <- renderUI({ | |
list( | |
renderPlot({ ## ggplot (Doesnt work) | |
ggplot(df, aes(x = words, y = number)) + geom_bar(stat = 'identity') | |
}), | |
renderPlot({ ## lattice (Doesnt work) | |
lattice::barchart(x = number ~ words, data = df) | |
}), | |
renderPlot({ ## deafult graphics plot. (WORKS) | |
graphics::barplot(df$number, names.arg = df$words) | |
}) | |
) | |
}) | |
}) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment