How to handle datasets with pictures inside?

Hi all

To improve customers experience, I would like to make a Shiny app in which we load an excel file like this.

The goal is that the customer first filters on "Instrument" with radiobuttons, then on "Error Code" with numberInput. The get the rest of the table on the screen. But most important is also to get the picture.

Filtering a dataset is not difficult for me, but I don't know how to get that picture with it.

eg: choosing "toestel 555" and code "111" should give the correct line of the file, but also the picture in that line.

Thanks in advance!

library(shiny)
library(tidyverse)
library(DT)
library(openxlsx)
ui <- fluidPage(
  DT::dataTableOutput("a_table"),
  downloadButton("dl_1")
)

server <- function(input, output, session) {
  my_data <- reactive({
    data.frame(
      text_col = letters[1:2],
      image_url_col = c(
        "https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1Mu3b?ver=5c31",
        "https://forum.posit.co/uploads/default/original/3X/b/a/bacfddc515a52beebdcf1e526c2c34aed6972133.png"
      )
    ) |>
      rowwise() |>
      mutate(
        shiny_image_col = as.character(img(src = image_url_col)),
        excel_image_col = paste0('=IMAGE("', image_url_col, '")')
      ) |>
      ungroup()
  })

  output$a_table <- DT::renderDataTable(
    {
      req(my_data()) |> select(text_col, shiny_image_col)
    },
    escape = FALSE
  )

  output$dl_1 <- downloadHandler(
    filename = function() {
      paste("test_", Sys.Date(), ".xlsx", sep = "")
    },
    content = function(file) {
      my_data <- req(my_data()) |> select(text_col, excel_image_col)
      wb <- createWorkbook()
      addWorksheet(wb, "testsheet")
      writeDataTable(wb, "testsheet", my_data)
      saveWorkbook(
        wb = wb,
        file = file
      )
    }
  )
}

shinyApp(ui, server)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.