Last active
February 11, 2020 21:37
-
-
Save MayaGans/4b4a72ead1cbf04be7f6c4904f9a5ef3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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