{"action":"created","issue":{"url":"https://api.github.com/repos/rstudio/shiny/issues/940","labels_url":"https://api.github.com/repos/rstudio/shiny/issues/940/labels{/name}","comments_url":"https://api.github.com/repos/rstudio/shiny/issues/940/comments","events_url":"https://api.github.com/repos/rstudio/shiny/issues/940/events","html_url":"https://github.com/rstudio/shiny/issues/940","id":103789625,"number":940,"title":"Generate datatable values dynamically based on inputs from another column","user":{"login":"davidzornek","id":13280056,"avatar_url":"https://avatars.githubusercontent.com/u/13280056?v=3","gravatar_id":"","url":"https://api.github.com/users/davidzornek","html_url":"https://github.com/davidzornek","followers_url":"https://api.github.com/users/davidzornek/followers","following_url":"https://api.github.com/users/davidzornek/following{/other_user}","gists_url":"https://api.github.com/users/davidzornek/gists{/gist_id}","starred_url":"https://api.github.com/users/davidzornek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidzornek/subscriptions","organizations_url":"https://api.github.com/users/davidzornek/orgs","repos_url":"https://api.github.com/users/davidzornek/repos","events_url":"https://api.github.com/users/davidzornek/events{/privacy}","received_events_url":"https://api.github.com/users/davidzornek/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-28T20:23:13Z","updated_at":"2015-09-02T02:21:54Z","closed_at":"2015-09-02T02:21:54Z","body":"I have created a datatable which has selectInput widgets in one of the columns. Another column of the datatable should take inputs given in the first column, and use them to look up a number from my data source. The inputs are binding correctly in Shiny, by using preDrawCallback and drawCallback functions, but lookup values are not updating when the inputs change. Strangely, they do update when I do the lookup in a separate data table. A reproducible example is here:\r\n\r\n    library(shiny)\r\n    library(DT)\r\n    \r\n    data <- data.frame(c(1:7),c(21:27))\r\n    \r\n    shinyApp(\r\n      server = shinyServer(function(input, output) {\r\n          output$table <- DT::renderDataTable({\r\n            \r\n            Rows <- c(1:7)\r\n            temp <- data.frame(Rows)  \r\n            temp[,\"Item\"] <- \"\"\r\n            temp[,\"Value\"] <- \"\"\r\n            temp$Rows <- NULL\r\n            \r\n            sapply(1:7, FUN = function(i) {\r\n              temp$Item[i] <<- as.character(selectInput(paste(\"Item.1.1\",i, sep = \".\"), \"\",\r\n                                                           choices = setNames(c(1:7),c(1:7)),\r\n                                                           selected = 1,\r\n                                                           multiple = FALSE))\r\n            })\r\n            \r\n             sapply(1:7, FUN = function(i) {\r\n               temp$Value[i] <<- data[eval(parse(text = paste(\"input$Item.1.1\",i, sep = \".\"))),2]\r\n             })\r\n            \r\n            datatable(temp, escape = FALSE, rownames = FALSE,\r\n                      options = list(sort = FALSE, paging = FALSE, searching = FALSE, dom = 't',\r\n                                     columnDefs = list(list(className = 'dt-center', targets = 0:1)),\r\n                                     preDrawCallback = JS('function() { Shiny.unbindAll(this.api().table().node()); }'),\r\n                                     drawCallback = JS('function() { Shiny.bindAll(this.api().table().node()); } ')\r\n                      ))\r\n        }, server = FALSE)\r\n      }),\r\n      ui = fluidPage(\r\n        dataTableOutput(\"table\")\r\n      )\r\n    )\r\n\r\nThat gives the error \"Error in temp$Value[i] <<- data[eval(parse(text = paste(\"input$Item.1.1\",  : \r\n  replacement has length zero\".\r\n\r\nI have tried adding this to server:\r\n\r\n    test <- reactive({\r\n                  data.frame(c(ifelse(is.null(input$Item.1.1.1),\"\",data[eval(parse(text = paste(\"input$Item.1.1\",1, sep = \".\"))),2]),\r\n                    ifelse(is.null(input$Item.1.1.2),\"\",data[input$Item.1.1.2,2]),\r\n                    ifelse(is.null(input$Item.1.1.3),\"\",data[input$Item.1.1.3,2]),\r\n                    ifelse(is.null(input$Item.1.1.4),\"\",data[input$Item.1.1.4,2]),\r\n                    ifelse(is.null(input$Item.1.1.5),\"\",data[input$Item.1.1.5,2]),\r\n                    ifelse(is.null(input$Item.1.1.6),\"\",data[input$Item.1.1.6,2]),\r\n                    ifelse(is.null(input$Item.1.1.7),\"\",data[input$Item.1.1.7,2])))\r\n                })\r\n              \r\nThen, when I comment out the appropriate sapply within my renderDataTable and instead assign temp[,\"Value\"] <- test(), I get 21 down the second column of my datatable, and it does not change when the selectInputs are changed.\r\n\r\nAs a test, I have tried including this in my serve, coupled with a corresponding dataTableOutput() in my ui:\r\n\r\n                 output$test1 <- DT::renderDataTable({\r\n                   test()\r\n                 })\r\n\r\ntest1 behaves as expected if and only if the second sapply is commented out inside of renderDataTable. If it is not commented out, both tables have a column of unresponsive 21s.\r\n\r\nThis has been driving me batty all day, so any thoughts would improve my life greatly!"},"comment":{"url":"https://api.github.com/repos/rstudio/shiny/issues/comments/136915847","html_url":"https://github.com/rstudio/shiny/issues/940#issuecomment-136915847","issue_url":"https://api.github.com/repos/rstudio/shiny/issues/940","id":136915847,"user":{"login":"yihui","id":163582,"avatar_url":"https://avatars.githubusercontent.com/u/163582?v=3","gravatar_id":"","url":"https://api.github.com/users/yihui","html_url":"https://github.com/yihui","followers_url":"https://api.github.com/users/yihui/followers","following_url":"https://api.github.com/users/yihui/following{/other_user}","gists_url":"https://api.github.com/users/yihui/gists{/gist_id}","starred_url":"https://api.github.com/users/yihui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yihui/subscriptions","organizations_url":"https://api.github.com/users/yihui/orgs","repos_url":"https://api.github.com/users/yihui/repos","events_url":"https://api.github.com/users/yihui/events{/privacy}","received_events_url":"https://api.github.com/users/yihui/received_events","type":"User","site_admin":false},"created_at":"2015-09-02T02:21:54Z","updated_at":"2015-09-02T02:21:54Z","body":"Cross-posted in shiny-discuss https://groups.google.com/forum/#!msg/shiny-discuss/a3gVXsDX8FE/vFvD_xudBwAJ and http://stackoverflow.com/q/32279266/559676, so closing this issue. Will answer on SO. "}}