Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
484 views
in Technique[技术] by (71.8m points)

caching plots in R/Shiny

Just wondering if there are tricks/ways in which I could cache the plots being generated through our shiny app.

Background:

We are doing somewhat compute intensive computations which finally result in a plot. I am already caching(using memoise) the computations done, globally in shiny but it still takes about .75 seconds to render a plot. I was just wondering if we can decrease that time by removing the time it takes to render an image and if there are slick ways of already doing it.

More details:

I am using grid to create the plot(heatmap in this case. Ideally would like the caching to be disk based as storing plots in memory wont scale up.

Thanks! -Abhi

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Assuming you are using ggplot (which with Shiny, I would bet is a fair assumption).

  1. Create an empty list to store your grob, say Plist.
  2. When a user request a graph, create a string hash based on the shiny inputs
  3. Check if the graph is already saved, eg hash %in% names(Plist)
  4. If yes, serve up that graph
  5. If no, generate the graph, save the grob to the list, name the element by the hash, eg, Plist[hash] <- new_graph

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...