Skip to content

Instantly share code, notes, and snippets.

@MayaGans
Last active February 11, 2020 21:37
Show Gist options
  • Save MayaGans/4b4a72ead1cbf04be7f6c4904f9a5ef3 to your computer and use it in GitHub Desktop.
Save MayaGans/4b4a72ead1cbf04be7f6c4904f9a5ef3 to your computer and use it in GitHub Desktop.
library(shiny)
my_df <- data.frame(values = c("A", "B", "C"))
ui <- fluidPage(
div(id = "my_select"),
tags$script(src = "select.js")
)
server <- function(session, input, output) {
session$sendCustomMessage("my_data", my_df$values)
}
shinyApp(ui = ui, server = server)
/* I want to use the values from my_df */
Shiny.addCustomMessageHandler('my_data', function(color) {
// the dataframe column is imported as an array
console.log(color)
my_array = Object.values(color)
document.getElementById("my_select").innerHTML =
`<select>
${my_array.map(createOption).join("")}
</select>`
});
function createOption(opt) {
return `<option value=${opt}>${opt}</option>`
}
/*
But can I make this work:
Shiny.addCustomMessageHandler('my_data', function(color) {
// the dataframe column is imported as an array
console.log(color)
my_array = Object.values(color)
});
document.getElementById("my_select").innerHTML =
`<select>
${my_array.map(createOption).join("")}
</select>`
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment