R语言 在弹出窗口中放大图-闪亮的应用程序

ddrv8njm  于 2023-05-26  发布在  其他
关注(0)|答案(1)|浏览(119)

我想把一个动作按钮,缩放和放大图像在我闪亮的应用程序。请参阅下面的代码,shiny应用根据用户的选择渲染两个图像“space_1.jpg”和“space_2.jpg”(已经创建)。这个想法将允许用户在弹出窗口中放大图像。我不知道如何让它成为可能。非常感谢你的帮助

library(shiny)
library(shinyWidgets)
ui <- fluidPage(

sidebarPanel(width=6,
    radioButtons("choice", label = h4("Choose"),choices = c("space_1","space_2"), selected = "space_1"),
    dropdown(downloadButton(outputId = "down_image_test",label = "Download plot"),size = "xs",icon = icon("download", class = "opt"), up = TRUE),
    actionBttn(inputId = "zoom_image_test",icon = icon("search-plus", class = "opt"),style = "fill",color = "danger",size = "xs")
           ),

mainPanel(h2("main panel"),imageOutput('image_test'))

    )

server <- function(input, output){

    output$image_test <- renderImage({
        nam=paste0(getwd(),"/",input$choice,".jpg")
        list(src = nam,height = 200)}, deleteFile = FALSE)

    output$down_image_test <- downloadHandler(
        filename = "test.jpg",
        content = function(file) {
        nam=paste0(getwd(),"/",input$choice,".jpg")
        file.copy(nam, file)
    })  

}

shinyApp(ui,server)
zysjyyx4

zysjyyx41#

也许是这样的:
代码非常科塞,你可以自己修改。

library(shiny)

ui <- fluidPage(
  titlePanel("Enlarge Plot Demo"),
  sidebarLayout(
    sidebarPanel(
      actionButton("enlargeButton", "Enlarge")
    ),
    mainPanel(
      plotOutput("plot", height = "400px")
    )
  )
)

server <- function(input, output) {
  output$plot <- renderPlot({
    plot(cars)
  })
  
  observeEvent(input$enlargeButton, {
    showModal(modalDialog(
      tags$head(tags$style(HTML(".modal-dialog { width: 100vw; }"))),
      plotOutput("enlargedPlot", height = "800px"),
    ))
    
    output$enlargedPlot <- renderPlot({
      plot(cars)
    })
  })
  
}

shinyApp(ui, server)

相关问题