【问题标题】:imageOutput Shiny, limited to one image (the last one)imageOutput Shiny,仅限于一张图片(最后一张)
【发布时间】:2016-01-11 03:11:30
【问题描述】:

我正在使用imageOutput 函数将几张图片放入一个闪亮的应用程序中,如下所示,但只显示最后一张图片。这是因为imageOutput 仅限于一张图片吗?

# ui.R
library(shiny)
library(png)
library(DT)

shinyUI(navbarPage(
  title = " Nanoproject",

  # first panel , create table of the peaksTable dataframe 
  tabPanel('Peak Table' , 
           dataTableOutput("table1")),

  # second panel
  tabPanel('Peak Images' , 
           imageOutput("image1",width=100,height=100),
           imageOutput("image2",width=100,height=100),
           imageOutput("image3",width=100,height=100),
           imageOutput("image4",width=100,height=100),
           imageOutput("image5",width=100,height=100),
           imageOutput("image6",width=100,height=100),
           imageOutput("image7",width=100,height=100),
           imageOutput("image8",width=100,height=100),
           imageOutput("image9",width=100,height=100),
           imageOutput("image10",width=100,height=100),
           imageOutput("image11",width=100,height=100)
  ),

  # third panel

  tabPanel('Event Table' , dataTableOutput("table3")),

  # fourth panel
  tabPanel('Event Images')
))

#server.R
# the peak images, 1-12   
output$image1 <- renderImage({list(src=paste0(imagePath,"/peak1.png"))},deleteFile=FALSE)
output$image2 <- renderImage({list(src=paste0(imagePath,"/peak2.png"))},deleteFile=FALSE)
output$image3 <- renderImage({list(src=paste0(imagePath,"/peak3.png"))},deleteFile=FALSE)
output$image4 <- renderImage({list(src=paste0(imagePath,"/peak4.png"))},deleteFile=FALSE)
output$image5 <- renderImage({list(src=paste0(imagePath,"/peak5.png"))},deleteFile=FALSE)
output$image6 <- renderImage({list(src=paste0(imagePath,"/peak6.png"))},deleteFile=FALSE)
output$image7 <- renderImage({list(src=paste0(imagePath,"/peak7.png"))},deleteFile=FALSE)
output$image8 <- renderImage({list(src=paste0(imagePath,"/peak8.png"))},deleteFile=FALSE)
output$image9 <- renderImage({list(src=paste0(imagePath,"/peak9.png"))},deleteFile=FALSE)
output$image10 <- renderImage({list(src=paste0(imagePath,"/peak10.png"))},deleteFile=FALSE)
output$image11 <- renderImage({list(src=paste0(imagePath,"/peak11.png"))},deleteFile=FALSE)

但是,只有 LAST 图像被加载

【问题讨论】:

    标签: r shiny rstudio


    【解决方案1】:

    图片文件的实际大小是多少?

    我尝试了以下代码(filename1、filename2、filename3 只是图像文件的一些本地路径名),它在图像尺寸较小且不工作(呈现重叠方式)图像时工作正常尺寸非常大。看起来只渲染了最后一张图像,但实际上所有其他图像都隐藏在下面。

    library(shiny)
    
    ui <- fluidPage('Peak Images',
                   imageOutput("image1"),
                   imageOutput("image2"),
                   imageOutput("image3"))
    
    server <- function(input, output) {
      output$image1 <- renderImage({
        list(src = filename1)
      }, deleteFile = FALSE)
      output$image2 <- renderImage({
        list(src = filename2)
      }, deleteFile = FALSE)
      output$image3 <- renderImage({
        list(src = filename3)
      }, deleteFile = FALSE)
    }
    
    shinyApp(ui = ui, server = server)
    

    【讨论】:

    • 它们的大小约为 100KB,但它们是又高又宽的图像。
    • 图像的像素宽度和高度很重要。当我有 240 x 340 尺寸时,所有三个图像都是垂直渲染的。当图像大小为 25xx 乘以 19xx 时,它们都在另一个之上渲染。
    • 尝试我的代码提供相同的图像文件,并将该图像文件调整为更小的尺寸。
    • 第二张图片看起来确实与第一张图片的大部分重叠。我怎样才能改变它
    【解决方案2】:

    高度和宽度设置为“自动”,从而解决了问题。感谢 user3949008 帮助我意识到需要更改高度和宽度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-15
      • 2012-02-10
      • 1970-01-01
      相关资源
      最近更新 更多