0

I recently used Markdown and Shiny in R Studio v1.1.456 (R version 3.4.3) to create an output html file. The html file simply produces a plot which the user can update by changing some basic inputs. I created a simple R Markdown (.rmd) script below for testing purposes. I simply want to add a prompt (checkbox?) to the html file that allows the user (i.e. me!) to save certain plots locally as a jpeg.

NOTE: This is just a simple local application that I run on my machine. I do not want to host a Shiny app or use servers etc.

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

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

```{r Libraries and Data, include=FALSE}
library(ggplot2)
x <- c(1,3,4,5,8,9,12,12,13,17)
y <- c(30,32,35,36,38,38,40,41,44,47)
z <- rep(0,10)
DF <- data.frame(x,y,z)
```

```{r model, echo=FALSE}
numericInput("coef1","input coefficient 1:",1.5)
numericInput("coef2","input coefficient 2:",3)

renderPlot({
  coef1 <- input$coef1
  coef2 <- input$coef2

  for (i in 1:10){
    DF$z[i] <- sqrt((coef1*(DF$x[i])+coef2*(DF$y[i])))
  }

  plot <- ggplot(data=DF,aes(x=x,y=y)) + geom_point()
  plot + geom_line(aes(x=x,y=z),colour="red") 
})
```
Andrew15
  • 39
  • 9
  • A similar question can be found here (https://stackoverflow.com/questions/52029794/r-shiny-saving-reactive-ggplots), however they are using a Shiny App, I am just working locally. Again, new to Markdown and Shiny but I think this makes sense. – Andrew15 Mar 14 '19 at 17:52
  • webshot might help, e.g. this for markdown: https://rdrr.io/cran/webshot/man/rmdshot.html – Tonio Liebrand Mar 14 '19 at 18:53
  • Yes, possible option. Although it doesn't seem clear in the documentation whether I can select a particular image to 'screenshot' vs. the whole page. I'll continue to research/test. – Andrew15 Mar 15 '19 at 13:36

0 Answers0