Use custom visual in Shiny with adaptive constrain

2019-08-21 18:24发布

Say I wanted to use a custom image or shapefile in an interactive environment (like R Shiny) such as this image of a paper airplane:

paper airplane

I would also be willing to draw the image myself in the program to allow for full control.

But the overall goal would be to allow a user to drag the edges of the image and the program could keep track of the size of the changes for each dimension (say wingspan of the paper airplane)

Would Shiny be a possibility here, or do I need to use another program? I would also want some statistics of the changes available to the user.

Does anyone have any similar examples of such a thing, or can point me in the right direction?

标签: r shiny frontend
1条回答
ら.Afraid
2楼-- · 2019-08-21 18:38

Like i wrote in the comment you could use the shinyjqui package and read the session info of the user.

A reproducible example can be found below:

library(shiny)
library(shinyjqui)
library(ggplot2)
server <- function(input, output, session){
  global <- reactiveValues(width = 400, height = 400)

  observe({
    print(session)
    if(!is.null(session$clientData[["output_plot1_height"]])){
      global$height <- session$clientData[["output_plot1_height"]]
      global$width <- session$clientData[["output_plot1_width"]]
    }
  })

  output$plot1 <- renderImage({
    outfile <- tempfile(fileext='.png')
    png(outfile, width = global$width, height = global$height)
    hist(rnorm(200))
    dev.off()
    list(src = outfile)
  }, deleteFile = TRUE)

  output$clientdataText <- renderText({
    paste("height is ", global$height, "width is", global$width)
  })


  }

ui <- fluidPage(
    verbatimTextOutput("clientdataText"),
    jqui_resizabled(plotOutput("plot1"))
)


shinyApp(ui, server)
查看更多
登录 后发表回答