我正在尝试创建一个用户可以输入一些数据并对其进行分析的网络应用。如果用户不想上传数据而宁愿看一个例子,我想显示一个图像而不是一个图。有没有办法根据用户输入决定何时使用renderPlot
和renderImage
?到目前为止我的解决方案是:
(在流动页面的ui.R
内):
conditionalPanel(
condition = "output.useExample == true",
imageOutput("allPCA.image")
),
conditionalPanel(
condition = "output.useExample == false",
plotOutput("allPCA.plot")
)
我的输出中有两个函数:
output$allPCA.image <- renderImage({
list(src = "./static/pca.all.png",
contentType = 'image/png',
alt = "Example PCA")
}, deleteFile=FALSE)
output$allPCA.plot <- renderPlot({
plot(stuff))}
有办法做到这一点吗?
答案 0 :(得分:3)
对此示例的回答renderImage NOT DISPLAYING - R Shiny (only alt text)您可以执行以下操作:
rm(list = ls())
library(shiny)
runApp(list(
ui = fluidPage(
titlePanel("Plot or Example?"),
sidebarLayout(
sidebarPanel(
selectInput("my_choices", "Example or Plot",choices = c("Plot", "Example"), selected = 1),width=2),
mainPanel(
conditionalPanel(
condition = "input.my_choices == 'Plot'",
plotOutput('my_test1')
),
conditionalPanel(
condition = "input.my_choices == 'Example'",
uiOutput("my_test2")
)
)
)
),
server = function(input, output) {
output$my_test1 <- renderPlot({plot(runif(100))})
output$my_test2 <- renderUI({
images <- c("http://www.i2symbol.com/images/abc-123/o/white_smiling_face_u263A_icon_256x256.png")
tags$img(src= images)
})
}
))