闪亮:弹出窗口中的绘图结果 [英] Shiny: plot results in popup window

查看:18
本文介绍了闪亮:弹出窗口中的绘图结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SHINY构建一个Web应用程序,我希望在弹出窗口中显示R函数的结果图 窗口,而不是在主面板中。 例如,对于下面的示例(来自http://shiny.rstudio.com/articles/action-buttons.html),单击"Go"按钮 将在弹出窗口中显示相同的绘图。

我试图添加一些javascript,但尚未成功.有人能帮忙吗?

提前感谢您!

library(shiny)
ui <- fluidPage(
    actionButton("go", "Go"),
    numericInput("n", "n", 50),
 plotOutput("plot")
)
server <- function(input, output) {
  randomVals <- eventReactive(input$go, {
  runif(input$n)
  })
  output$plot <- renderPlot({
   hist(randomVals())
 })
}
shinyApp(ui, server)

推荐答案

查看提供modal弹出窗口的shinyBS包。下面的示例显示了单击按钮时的绘图。

编辑-将下载按钮添加到模态

rm(list = ls())
library(shiny)
library(shinyBS)

shinyApp(
  ui =
    fluidPage(
      sidebarLayout(
        sidebarPanel(numericInput("n", "n", 50),actionButton("go", "Go")),
        mainPanel(
          bsModal("modalExample", "Your plot", "go", size = "large",plotOutput("plot"),downloadButton('downloadPlot', 'Download'))
        )
      )
    ),
  server =
    function(input, output, session) {

      randomVals <- eventReactive(input$go, {
        runif(input$n)
      })

      plotInput <- function(){hist(randomVals())}

      output$plot <- renderPlot({
        hist(randomVals())
      })

      output$downloadPlot <- downloadHandler(
        filename = "Shinyplot.png",
        content = function(file) {
          png(file)
          plotInput()
          dev.off()
        }) 

    }
)

这篇关于闪亮:弹出窗口中的绘图结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆