- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法使用 renderImage()
来处理 .svg 文件。我的最小示例( adapted from the corresponding RStudio-tutorial ):
shinyUI(pageWithSidebar(
headerPanel("renderSVG example"),
sidebarPanel(
sliderInput("obs", "Number of observations:",
min = 0, max = 1000, value = 500),
actionButton("savePlot", "savePlot")
),
mainPanel(
# Use imageOutput to place the image on the page
imageOutput("plot"),
imageOutput("plot_as_svg")
)
))
require("ggplot2")
library(svglite)
shinyServer(function(input, output, session) {
## create plot with renderPlot()
output$plot<- renderPlot({
hist(rnorm(input$obs), main="Generated in renderPlot()")
})
## create .svg file of the plot and render it with renderImage()
output$plot_as_svg <- renderImage({
# A temp file to save the output.
# This file will be removed later by renderImage
outfile <- tempfile(fileext='.svg')
# Generate the svg
svglite(outfile, width=400, height=300)
hist(rnorm(input$obs), main="Generated in renderImage()")
dev.off()
# Return a list containing the filename
list(src = outfile,
contentType = 'text/svg+xml',
width = 400,
height = 300,
alt = "This is alternate text")
}, deleteFile = TRUE)
})
有什么想法问题出在哪里吗?
最佳答案
我也遇到了同样的问题,而且我在网上找不到任何可以解决这个问题的方法,这令人沮丧。这是对我有用的解决方案:
shinyUI(pageWithSidebar(
headerPanel("renderSVG example"),
sidebarPanel(
sliderInput("obs", "Number of observations:",
min = 0, max = 1000, value = 500),
actionButton("savePlot", "savePlot")
),
mainPanel(
# Use imageOutput to place the image on the page
imageOutput("plot"),
imageOutput("plot_as_svg")
)
))
require("ggplot2")
shinyServer(function(input, output, session) {
## create plot with renderPlot()
output$plot<- renderPlot({
hist(rnorm(input$obs), main="Generated in renderPlot()")
})
## create .svg file of the plot and render it with renderImage()
output$plot_as_svg <- renderImage({
width <- session$clientData$output_plot_width
height <- session$clientData$output_plot_height
mysvgwidth <- width/96
mysvgheight <- height/96
# A temp file to save the output.
# This file will be removed later by renderImage
outfile <- tempfile(fileext='.svg')
# Generate the svg
svg(outfile, width=mysvgwidth, height=mysvgheight)
hist(rnorm(input$obs), main="Generated in renderImage()")
dev.off()
# Return a list containing the filename
list(src = normalizePath(outfile),
contentType = 'image/svg+xml',
width = width,
height = height,
alt = "My Histogram")
})
})
注意,我没有使用 svglite 包,只是使用 grDevices (base) 包中的 svg 设备。我还规范了源代码中的路径,因为我使用的是 Windows 计算机(我相信这会将我的源代码从正斜杠更改为反斜杠,但也许有人会对此发表评论)。
此外,我创建了四个新变量来容纳 svg 宽度和高度以及图像宽度和高度,以便仍然与页面保持流畅。我确信有比这更简单的解决方法,但我发现这是有效的。
关于 Shiny 应用程序中的 renderImage() 和 .svg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39093777/
renderImage尝试从 Internet 渲染图像时不起作用。当图像在本地机器上时它起作用。 output$myImage <- renderImage({ pfad <- "htt
我正在使用非常有用的 PDFBox 来构建一个简单的 pdf 印章 GUI。 但是,我注意到某个特定文档存在严重问题。 当我为渲染指定特定比例因子时,预期的输出图像大小会有所不同。 什么是更糟糕的?生
我有一个应用程序,它根据用户输入显示数据和图片。我的 ui 中有以下代码: selectInput("var", label = "Choose a pen
使用下面的代码,我只会显示 alt 文本。 关于可能是什么问题的任何建议? 从服务器.R: output$face .085) { return(list( src = "http://www.i2
我对 renderImage 的 deleteFile = FALSE 参数有疑问。简而言之,它无论如何都会删除图像文件。 作为一个简短的测试示例,我有 ui.R library(shiny)
我无法使用 renderImage() 来处理 .svg 文件。我的最小示例( adapted from the corresponding RStudio-tutorial ): ui.R shin
我正在使用 renderImage() 将一堆预渲染图像调用到 Shiny 应用程序中。我希望这些 png 图像位于侧边栏中,并根据浏览器或设备类型(例如 Chrome、Android)调整宽度和高度
我是一名优秀的程序员,十分优秀!