R-shiny 中的并排图像

side by side images in R-shiny

我有 11 张图片。我想在不同的选项卡中显示它们。 其中一张图片需要紧挨着其他 10 张图片。 我如何在 R-Shiny 中做到这一点?

执行以下操作有两个问题:

  1. 似乎一张图像不能显示多次,在这种情况下 repeated_image 是通过 server.R 中的 renderImage() 渲染的。

  2. 如果我用10个不同的名字读了10次需要重复的图像,那么另一个问题是下面的代码会将它们放在彼此之上,而不是彼此相邻:

    tabPanel("Some title here", fluidRow(tabBox(tabPanel("Tab 1", 图像输出("image_1"), br(),br(),br(),br(), 图像输出("repeated_image"), 高度 = 700), tabPanel("Tab 2", 图像输出("image_2"), br(), br(), 图像输出("repeated_image"), 高度=700), 宽度 = 12 ) ) )

有什么建议吗?我可以在渲染图像期间在服务器中执行此操作吗?像

renderImage(image_1, repeated_image)
renderImage(image_2, repeated_image)

我以非常静态的方式尝试了相同的方法,其中所有 imageOutput 都是单独编写的。

两种并排放置图像的方法- TabBox 和基于列。

Column based我拍了一张小图128*128 对于 TabBox,您可以选择任何尺寸的图片。 在这两种情况下,您都可以使用宽度和高度参数根据您的要求进行更改。 如果这能解决您的问题,请告诉我。 ui.R

library(shiny)
library(shinydashboard)

dashboardPage(
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(),
  dashboardBody(
   fluidRow(
     column(1,imageOutput("img1")),
     column(1,imageOutput("img2")),
     column(1,imageOutput("img3")),
     column(1,imageOutput("img4")),
     column(1,imageOutput("img5")),
     column(1,imageOutput("img6")),
     column(1,imageOutput("img7")),
     column(1,imageOutput("img8")),
     column(1,imageOutput("img9")),
     column(1,imageOutput("img10")),
     column(1,imageOutput("img11"))
   ),
   fluidRow(
            tabBox(
              tabPanel("Tab 1",
                   fluidRow(
                      column(6,
                             imageOutput("tabimg1_1")
                             ),
                      column(6,
                             imageOutput("tabimg1_2")
                             )
                   )
                   ),
              tabPanel("Tab 2",imageOutput("tabimg2")),
              tabPanel("Tab 3",imageOutput("tabimg3")),
              tabPanel("Tab 4",imageOutput("tabimg4")),
              tabPanel("Tab 5",imageOutput("tabimg5")),
              tabPanel("Tab 6",imageOutput("tabimg6")),
              tabPanel("Tab 7",imageOutput("tabimg7")),
              tabPanel("Tab 8",imageOutput("tabimg8")),
              tabPanel("Tab 9",imageOutput("tabimg9")),
              tabPanel("Tab 10",imageOutput("tabimg10")),
              tabPanel("Tab 11",imageOutput("tabimg11"))
            )
   )
  )
)

Server.R

    library(shiny)
    library(shinydashboard)


    shinyServer(function(input,output){

    filename <- normalizePath(file.path('./www/images','rstudio.png'))
    tabfilename<-normalizePath(file.path('./www/images','studio logo.jpg'))

    output$img1<-renderImage({
      list(src = filename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)

    output$img2<-renderImage({
      list(src = filename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)


    output$img3<-renderImage({
      list(src = filename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)

    output$img4<-renderImage({
      list(src = filename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)

    output$img5<-renderImage({
      list(src = filename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)

    output$img6<-renderImage({
      list(src = filename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)
    output$img7<-renderImage({
      list(src = filename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)
    output$img8<-renderImage({
      list(src = filename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)
    output$img9<-renderImage({
      list(src = filename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)

    output$img10<-renderImage({
      list(src = filename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)
    output$img11<-renderImage({
      list(src = filename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)


    output$tabimg1_1<-renderImage({
  list(src = tabfilename,
       contentType = 'image/png',
       alt = "This is alternate text")
}, deleteFile = FALSE)

output$tabimg1_2<-renderImage({
  list(src = tabfilename,
       contentType = 'image/png',
       alt = "This is alternate text")
}, deleteFile = FALSE)

    output$tabimg2<-renderImage({
      list(src = tabfilename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)

    output$tabimg3<-renderImage({
      list(src = tabfilename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)

    output$tabimg4<-renderImage({
      list(src = tabfilename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)
    output$tabimg5<-renderImage({
      list(src = tabfilename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)
    output$tabimg6<-renderImage({
      list(src = tabfilename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)
    output$tabimg7<-renderImage({
      list(src = tabfilename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)
    output$tabimg8<-renderImage({
      list(src = tabfilename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)
    output$tabimg9<-renderImage({
      list(src = tabfilename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)
    output$tabimg10<-renderImage({
      list(src = tabfilename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)
    output$tabimg11<-renderImage({
      list(src = tabfilename,
           contentType = 'image/png',
           alt = "This is alternate text")
    }, deleteFile = FALSE)

    })