title: Serve arbitrary image files through plumber
body: <p>Provided I have a saved image file, how do I serve them through plumber?</p>
  
  <p>For instance, this works without issues</p>
  
  <pre><code># save this as testPlumb.R
  
  library(magrittr)
  library(ggplot2)
  
  #* @get /test1
  #* @png
  test1 = function(){
      p = data.frame(x=1,y= 1) %&gt;% ggplot(aes(x=x,y=y)) + geom_point()
      print(p)
  }
  </code></pre>
  
  <p>and run </p>
  
  <pre><code>plum = plumber::plumb('testPlumb.R')
  plum$run(port=8000)
  </code></pre>
  
  <p>and if you go to <a href="http://localhost:8000/test1" rel="nofollow noreferrer">http://localhost:8000/test1</a>, you'll see the plot being served.</p>
  
  <p>But I was not able to find a way to serve an image file</p>
  
  <pre><code>#* @get /test2
  #* @png
  test2 = function(){
      p = data.frame(x=1,y= 1) %&gt;% ggplot(aes(x=x,y=y)) + geom_point()
      ggsave('file.png',p)
  
      # code that modifies that file a little that doesn't matter here
  
      # code that'll help me serve the file
  }
  </code></pre>
  
  <p>In place of <code>code that'll help me serve the file</code> above, I have tried <code>include_file</code> as suggested <a href="https://stackoverflow.com/questions/44185675/get-file-through-api-call-r-plumber">here</a> but that failed. </p>
  
  <p>Since the <code>code that modifies that file a little that doesn't matter here</code> part is using the magick package, I have also tried serving magick objects using <code>print</code> but that also have not been successful.</p>
  
  <p>For instance </p>
  
  <pre><code>#* @get /test3
  #* @png
  test3 = function(){
      p = data.frame(x=1,y= 1) %&gt;% ggplot(aes(x=x,y=y)) + geom_point()
      ggsave('file.png',p)
      fig = image_read(file)
      fig = image_trim(fig)
      print(fig) # or just fig
  }
  </code></pre>
  
  <p>results in <code>{"error":["500 - Internal server error"],"message":["Error in file(data$file, \"rb\"): cannot open the connection\n"]}</code></p>