4

I am currently working on an Shiny app with the amazing package svgPanZoom and I have two questions which remain unsolved for me:

(1) is it possible to customize the size of the graph dynamically. I tried to do that following the code (as in https://stackoverflow.com/questions/33522860/svgplot-error-in-shiny):

library(shiny)
library(svglite)
library(svgPanZoom)
library(ggplot2)
library(plyr)

data.df <- data.frame(Plant = c("Plant1", "Plant1", "Plant1", "Plant2", "Plant2", 
                                "Plant2"), Type = c(1, 2, 3, 1, 2, 3), Axis1 = c(0.2, -0.4, 0.8, -0.2, -0.7, 
                                                                                 0.1), Axis2 = c(0.5, 0.3, -0.1, -0.3, -0.1, -0.8))

ui <- shinyUI(bootstrapPage(

  svgPanZoomOutput(outputId = "main_plot")

))

server = shinyServer(function(input, output) {
  output$main_plot <- renderSvgPanZoom({
    p <- ggplot(data.df, aes(x = Axis1, y = Axis2, shape = Plant, color = Type)) + geom_point(size = 5)
    svgPanZoom(p, controlIconsEnabled = T, width = 10, height = 16)
  })
})

runApp(list(ui=ui,server=server))

but nothing happened :( Do you have an idea ?

(2) Do you know if it could be possible to include a locator in this code (as in PlotOutput)

The main idea is to plot a picture (of cells) in an orthonormed system and that user clicks on the picture to locate the nucleus of the cells. Sometimes the cells are very small on the picture so the user may need to zoom (that's why I use svgPanZoom). Thus, the X and Y that I would like to get are those in the whole orthonormed system even if the user uses the zoom

I had a look at Cursor location after zoom using svg-pan-zoom but it seems not to be from R

Thank you very much for your ideas !

Have a nice sunday evening !

Cha

Community
  • 1
  • 1
Charlotte Sirot
  • 931
  • 1
  • 8
  • 11
  • Interesting question. I have to make the observation that basing your code on code from an unsolved problem was probably bound not to work though. Regarding your 2nd question I'm pretty sure I know what you mean, but could you clarify the exact definition of the word "locator"? You mean the X, Y co-ordinates of the mouse pointer? So if someone is clicking the zoom button it would be the location of the zoom button (not the center of the visible image, which is presumably where they are looking)? – Hack-R Oct 02 '16 at 15:11
  • Hi Hack ! Thank you for your answer. For the first question, I pick a script which is correctly running. The problem is that the graph has the same dimension even if I change the width and height parameters :S However When I looked at the documentation it seems that the function is written correctly, no ? (From the help of the package) svgPanZoom( svglite:::inlineSVG( show(m ) # will have to manually size the svg device , height = 10, width = 16 ) ) – Charlotte Sirot Oct 02 '16 at 15:34
  • For the second point, I edit my post to be clearer in the description of my problem, I really hope it is more understandable now ... :) – Charlotte Sirot Oct 02 '16 at 15:37

1 Answers1

2

Concerning 1): Your link doesnt work anymore. But maybe the amazing shinyjqui package is of interest for you. You can add the jqui_resizabled() function in your ui. In your example it would be: jqui_resizabled(svgPanZoomOutput(outputId = "main_plot")). You will find a small grey symbol in the lower left hand corner of your output.

See a small gif example (section: resizable) and other interesting functions here: https://github.com/Yang-Tang/shinyjqui.

Full code would read:

library(shiny)
library(svglite)
library(svgPanZoom)
library(ggplot2)
library(plyr)
library(shinyjqui)

data.df <- data.frame(Plant = c("Plant1", "Plant1", "Plant1", "Plant2", "Plant2", 
                                "Plant2"), Type = c(1, 2, 3, 1, 2, 3), Axis1 = c(0.2, -0.4, 0.8, -0.2, -0.7, 
                                                                                 0.1), Axis2 = c(0.5, 0.3, -0.1, -0.3, -0.1, -0.8))

ui <- shinyUI(bootstrapPage(

  jqui_resizabled(svgPanZoomOutput(outputId = "main_plot"))

))

server = shinyServer(function(input, output) {
  output$main_plot <- renderSvgPanZoom({
    p <- ggplot(data.df, aes(x = Axis1, y = Axis2, shape = Plant, color = Type)) + geom_point(size = 5)
    svgPanZoom(p, controlIconsEnabled = T, width = 10, height = 16)
  })
})

runApp(list(ui=ui,server=server))

For 2) i am unsure. One could try adding a click-listener, but it would be a rather ugly work around. Maybe smd else knows a better way.

Tonio Liebrand
  • 17,189
  • 4
  • 39
  • 59
  • The package seems rather interesting, however, the issue with the ggplot remains the same. I started the bounty to achieve a way to fill the whole width with the svgPanZoomOutput as changing the width and the height does not affect the plot at all. – Jon Nagra Oct 30 '17 at 08:27