R/Shiny App将Plot写入RStudio中的Plot视图,而不是Shiny UI



我有一个闪亮的应用程序与plotOutput组件:

plotOutput("plot_data")

使用vis_dat库,我写plot_data如下:

observeEvent(input$missing, { # Click the Missing actionButton
v$plot_data <- vis_miss(new_data())
})  

output$plot_data <- renderPlot({
if (is.null(v$plot_data)) return()
v$plot_data
})

很好。现在,我还(尝试)使用pairs()函数编写相同的组件,如下所示:

observeEvent(input$pairs, {  # Click the Pairs actionButton
v$plot_data <- pairs(new_data()) 
})

我使用与前面相同的响应输出$plot_data调用,但这一次,pairs()输出将一个绘图写入RStudio绘图面板,而不是Shiny UI。我在其他类型的情节中也看到过这种情况。知道这是为什么吗?

R中的绘图函数,如hist()plot()pairs(),绘制的是图像,而不是绘图。所以我使用renderImage()函数如下:

output$image_data <- renderImage({
width  <- session$clientData$output_image_data_width
height <- session$clientData$output_image_data_height

outfile <- tempfile(fileext='.png')
png(outfile, width=width, height=height)
plot(new_data(), pch=20 , cex=1.5 , col="#69b3a2")
dev.off()

list(
src = outfile,
width = width,
height = height
)
}, 
deleteFile = TRUE
)

在RStudio中,它们看起来都像图形,但返回值并不相等。

最新更新