如何在 R shiny 中将图像包装为浮动 window

How to wrap up Image as a floating window in R shiny

我想开发一个功能,当打开开关时图像可以显示在页面外部,当关闭开关时图像隐藏。这是我的 showing/hiding 页面中图像的示例代码,但是如果我们可以使图像浮动 window 并且可以在现有应用程序页面周围移动?

library("shinydashboard")
library("shinyWidgets")

ui <- fluidPage(
  h4("Embedded image"),
  uiOutput("img"),
  fluidRow(
    tags$h4("Show and Hide Image"),
    materialSwitch(
      inputId = "get_image",
      label = "Show Image", 
      value = FALSE,
      status = "success"
    ),
  ),
)

server <- function(input, output, session) {
  
  observeEvent(input$get_image, {
    if(input$get_image == TRUE){
      output$img <- renderUI({
        tags$img(src = "https://www.r-project.org/logo/Rlogo.png")
      })
    }else{
      output$img <- NULL
    }
  })


}

shinyApp(ui, server)

是这样的吗?

library(shiny)
library("shinydashboard")
library("shinyWidgets")

ui <- fluidPage(
  h4("Embedded image"),
  uiOutput("img"),
  fluidRow(
    tags$h4("Show and Hide Image"),
    materialSwitch(
      inputId = "get_image",
      label = "Show Image", 
      value = FALSE,
      status = "success"
    ),
  ),
)

server <- function(input, output, session) {
  
  
  output$img <- renderUI({
    if(input$get_image)
      absolutePanel(
        tags$img(src = "https://www.r-project.org/logo/Rlogo.png", width = "512"),
        draggable = TRUE
      )
  })
  
  
}

shinyApp(ui, server)