【问题标题】:Dynamically rendering an image on Shiny在 Shiny 上动态渲染图像
【发布时间】:2020-04-04 09:23:39
【问题描述】:

我想根据用户在下拉选项中选择的值在我的闪亮应用中动态呈现图像。对于用户选择的每个名称,该名称将具有关联的 global_id。我想用这个 global_id 来找到一个以匹配 global_id 作为名称的图像,然后显示图像

这是我的数据样本(装箱)

  name     division      sex      global_id
   ab        small        male        901
   bc        middle       male        999
   cd        big          male        002
   def       small        male        123
   dgh       small        male        284
   fgh       middle       male        990

图像在我的 www 文件中的同一目录中。

这是我尝试过的

        dropdownButton(
          inputId = 'dropdownA',
          label='control',
          icon = icon("user",lib="glyphicon"),
          status='primary',
          circle=TRUE
        ),
        selectInput("dropdown","Boxer A",
                    choices = unique(boxing$division)),
        uiOutput("Names"),
        imageOutput("boxerA")


server <- function(input,output){
   output$boxerA <- renderImage({
       outimage <- tempfile(fileext = '.jpg')})

这会返回错误信息:

错误:$ 运算符对原子向量无效

图片应该出现在我的应用上的区域

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    要集成图像,您应该在renderImage 中返回一个列表对象,其中图像的路径为src

    output$plop <- renderImage({
      list(src ="path/to/image")
    })
    
    imageOutput("plop")
    

    请注意,renderImage 有一个 deleteFile 参数,这意味着图像在渲染后将被删除。

    两种绕过方法:

    【讨论】:

      【解决方案2】:

      要补充已经给出的答案,您还可以使用 uiOutput 和 renderUI 渲染图像。

      所以 uiOutput 生成所述图像,renderUI 接收用户选择的输入并生成您想要显示的图片

      这方面的一个例子是:

      #replace this
      imageOutput("boxerA")
      #with this
      uiOutput('Picture')
      #then add this to server
      renderUI({tags$img(src = *picfilename*)})
      

      【讨论】:

        猜你喜欢
        • 2017-06-26
        • 2023-03-03
        • 1970-01-01
        • 2018-02-24
        • 1970-01-01
        • 2018-11-18
        • 1970-01-01
        • 2021-10-07
        • 2017-01-04
        相关资源
        最近更新 更多