I successfully got a variable from Shiny server back to the client with the function session$sendCustomMessage in server.R
Now I want to use this leftChoices variable in the ui.R client to create a widget chooserInput to create a [custom input control][1] but this is not working [1]: http://shiny.rstudio.com/gallery/custom-input-control.html
I've tried to use Shiny.chooserInput but in vain. the script doesn't recognize chooserInput and I don't know how to make it work. Some help. Thanks
Here is ui.R
source("chooser.R")
library(shiny)
shinyUI(fluidPage(sidebarLayout(sidebarPanel(
fileInput("file1", "Choose file to upload",
accept = c('text/csv','.csv')
)
),
mainPanel(
tabPanel("Data",shiny::dataTableOutput("contents")),
tags$script(src = "initcsv.js"),
chooserInput("mychoice", "Available", "Selected ",
colnames(message.leftChoices) , c(), size = 10, multiple = TRUE
)
)
)
)
)
Here is ny server.R
library(shiny)
source("chooser.R")
shinyServer(function(input, output, session) {
data <- reactive ({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
read.csv(inFile$datapath)
})
observe({
session$sendCustomMessage(type = "MyDatasetUpdated",
message = list(
leftChoices=colnames(data())
)
)
})
output$contents <- renderDataTable(
data(), options = list(iDisplayLength = 5)
)
})
Here is INITCSV.JS
Shiny.addCustomMessageHandler("MyDatasetUpdated",
function(message) {
if (message.leftChoices != null)
//chooserInput("mychoice", "Available", "Selected ",
//c() , c(), size = 10, multiple = TRUE
// ),
alert(JSON.stringify(message.leftChoices));
})
source(chooser.R). The program won't recognize the function unless it is defined. It may be easier to help you if you could provide a complete reproducible example either using therunAppfunction or providing both ui.R and server.R? - cdeterman