r - 在 Shiny 上动态渲染图像

标签 r shiny

我想根据用户在下拉选项中选择的值在我的 Shiny 应用程序中动态渲染图像。对于用户选择的每个名称,该名称将具有关联的 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')})

这将返回错误消息:

Error: $ operator is invalid for atomic vectors

在我的应用程序中图片应该出现的区域

最佳答案

要添加到已经给出的答案中,您还可以使用 uiOutput 和 renderUI 渲染图像。

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

一个例子是:

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

关于r - 在 Shiny 上动态渲染图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59279963/

相关文章:

r - R Shiny 的mainPanel显示样式和字体

R:在 ggplot 中使用 rollmean 会在最后产生错误的下降

python - 列中的多个分类变量和准备

javascript - R Shiny 包中的父/子行

r - 在 Shiny 中将响应式(Reactive)数据表转换为 Kable

r - 生成下拉通知的函数 Shiny R

r - 我如何反转 R 中矩阵的二进制数字(0 和 1)?

R : data frame Randomize columns by row

r - 使用 purrr::reduce() 进行迭代

r - 如何在 Shiny 的仪表板中制作信息按钮