R Shiny: fast reactive image display -


i'm trying display images in shiny app reactively. i've done in server.r script with:

output$display.image <- renderimage({      image_file <- paste("www/",input$image.type,".jpeg",sep="")      return(list(       src = image_file,       filetype = "image/jpeg",       height = 520,       width = 696     ))    }, deletefile = false) 

but it's very slow.

however, very fast embed 1 of images ui.r script so:

tabpanel("live images", img(src = "img_type1.jpeg")) 

why there such difference? there way make reactive images appear faster?

hi can use conditionalpanel this, embed images 1 have true condition displayed :

tabpanel("live images",       conditionalpanel(condition = "input.image_type == 'img_type1'",                       img(src = "img_type1.jpeg")      ),      conditionalpanel(condition = "input.image_type == 'img_type2'",                       img(src = "img_type2.jpeg")      ) ) 

and change name of input image.type image_type because . have special meaning in javascript (as between input , image_type).

if have lot of images, can :

tabpanel("live images",           lapply(x = seq_len(10), fun = function(i) {            conditionalpanel(condition = paste0("input.image_type == 'img_type", i, "'"),                             img(src = paste0("img_type", i, ".jpeg"))            )          }) ) 

for example, images post tsperry (you can find on rbloggers too), can :

library("shiny") ui <- fluidpage(   tabsetpanel(     tabpanel("live images",           # 50 images display          lapply(x = seq_len(50), fun = function(i) {            # condition on slider value            conditionalpanel(condition = paste0("input.slider == ", i),                             # images on github                             img(src = paste0("https://raw.githubusercontent.com/pvictor/images/master/",                                              sprintf("%04d", i), "plot.png"))            )          }),          sliderinput(inputid = "slider", label = "value", min = 1, max = 50, value = 1,                       animate = animationoptions(interval = 100, loop = true))     )   ) )  server <- function(input, output) {  }  shinyapp(ui = ui, server = server) 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -