I am trying to create an action button in a Shiny DataTable that when clicked links to a specific Amazon product. I modeled my code after R Shiny: Handle Action Buttons in Data Table. When the button is clicked, I need the user to navigate to a specific Amazon product page based on the ASIN in the data.table row.
filteredData <- data.frame(
Name = c('Dilbert', 'Alice', 'Wally', 'Ashok', 'Dogbert'),
ASIN = c("B06Y4VRZTB",
"B06Y4WGPBB",
"B06Y4J9Z9V",
"B06Y4V169H",
"B06Y4TF1D1"),
stringsAsFactors = FALSE,
row.names = 1:5)
shinyInput <- function(FUN, len, id, ...) {
inputs <- character(len)
for (i in seq_len(len)) {
inputs[i] <- as.character(FUN(paste0(id, i), ...))
}
print(inputs)
inputs
}
df <- reactiveValues(data = data.frame(
filteredData %>% mutate(Amazon.Button = shinyInput(actionButton,
nrow(filteredData),
'button_',
label = "Amazon",
onclick = paste0("window.open('https://",
AmazonSiteLink,
"/gp/product/",
ASIN,
"/ref=as_li_tl?ie=UTF8&tag=",
AssociateTag, "')")))
), escape=FALSE)
The issue is that every button ends up with the same URL picking up only the first ASIN value. I want the ASIN value to be what is in the ASIN value for the row.
https://www.amazon.com/gp/product/B06Y4VRZTB/ref=as_li_tl?ie=UTF8&tag=my0000-00'
I tried to create the button with every row, but get other errors such at, "Warning: Error in mutate_impl: Column Amazon.Button
must be length 5 (the number of rows) or one, not 3"
df <- reactiveValues(data = data.frame(
filteredData %>% mutate(Amazon.Button = actionButton(inputId = paste0('button'),
label = "Amazon",
onclick = paste0("window.open('https://",
AmazonSiteLink,
"/gp/product/",
ASIN,
"/ref=as_li_tl?ie=UTF8&tag=",
AssociateTag, "')")))
), escape=FALSE)