R shiny bug

289 views
Skip to first unread message

Austin D Nguyen

unread,
Aug 28, 2015, 6:05:40 PM8/28/15
to Shiny - Web Framework for R

My server.R is below. When I try to make this (the mapurl) reactive to user input i see Error in as.vector(x, "character") : cannot coerce type 'closure' to vector of type 'character...error..

Is there anything that is wrong with the selectize parts?



shinyServer(function(input, output, session) {

mapurl <- reactive(mapurl <- session$registerDataObj(

name = 'Names',
iFile <- input$data1,
tFile <- read.table(iFile$datapath, header=TRUE, sep=input$sep, quote = ""),
filter = function(tFile, req){

  query -> parseQueryString(req$QUERY_STRING)
  ID = query$ID
  finally = dev.off()
}))

output$contents <- renderTable({

inFile <- input$data1

if (is.null(inFile))
  return(NULL)

read.table(inFile$datapath, header=TRUE, sep=input$sep, quote = "")

})

output$Plot <- renderPlot({ iFile <- input$data1

tFile <- read.table(iFile$datapath, header=TRUE, sep=input$sep, quote = "")
plot(c(1, 13), range(as.matrix(tFile)), type = 'n', xaxt = 'n', las = 1,
     xlab = 'Experimental Points', ylab = 'Flux and Impact')
matlines(t(tFile), type = 'l', lty = 1, col = 'gray')
axis(1, 1:13, colnames(tFile))

})

updateSelectizeInput( session, "ID", server = TRUE, choices = setdiff(rownames(tFile)), options = list(render = I(sprintf( "{ option: function(item, escape) { return '' + escape(item.value) + ''; } }", mapurl ))) ) })

Yihui Xie

unread,
Sep 1, 2015, 12:31:52 AM9/1/15
to Austin D Nguyen, Shiny - Web Framework for R
It is not a shiny bug, but a problem of your code (maybe by "bug" you
meant something else). You defined mapurl as a reactive, which is
essentially a function. Then in updateSelectizeInput(), you
sprintf('code', mapurl), which certainly won't work: 1) mapurl is a
function, and sprintf() cannot accept functions as input; 2) you don't
even have %s in the first argument value of sprintf().

If you want updateSelectizeInput() to use different mapurl's according
to input$data1, you may create mapurl and update the selectize input
inside an observe() or observeEvent() like this:

observeEvent(input$data1, {
mapurl <- session$registerDataObj(
....
)
updateSelectizeInput(
# use mapurl here
)
})


Regards,
Yihui
Reply all
Reply to author
Forward
0 new messages