{"action":"opened","issue":{"url":"https://api.github.com/repos/rstudio/shiny/issues/1586","repository_url":"https://api.github.com/repos/rstudio/shiny","labels_url":"https://api.github.com/repos/rstudio/shiny/issues/1586/labels{/name}","comments_url":"https://api.github.com/repos/rstudio/shiny/issues/1586/comments","events_url":"https://api.github.com/repos/rstudio/shiny/issues/1586/events","html_url":"https://github.com/rstudio/shiny/issues/1586","id":207834072,"number":1586,"title":"Modules and conditional panels","user":{"login":"bborgesr","id":6527540,"avatar_url":"https://avatars.githubusercontent.com/u/6527540?v=3","gravatar_id":"","url":"https://api.github.com/users/bborgesr","html_url":"https://github.com/bborgesr","followers_url":"https://api.github.com/users/bborgesr/followers","following_url":"https://api.github.com/users/bborgesr/following{/other_user}","gists_url":"https://api.github.com/users/bborgesr/gists{/gist_id}","starred_url":"https://api.github.com/users/bborgesr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bborgesr/subscriptions","organizations_url":"https://api.github.com/users/bborgesr/orgs","repos_url":"https://api.github.com/users/bborgesr/repos","events_url":"https://api.github.com/users/bborgesr/events{/privacy}","received_events_url":"https://api.github.com/users/bborgesr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-02-15T15:21:54Z","updated_at":"2017-02-15T15:21:54Z","closed_at":null,"body":"We have two bugs on this.\r\n\r\nIt's impossible to do the following (which I think is how everyone would go about using modules + conditional panels):\r\n\r\n```r\r\nconditionalPanel(\r\n  condition = paste0(\"input.\", ns(\"smooth\"), \" == true\"),\r\n   ...\r\n)\r\n```\r\n\r\nbecause\r\n\r\n1. Since the namespacing that `ns` provides for modules includes a dash (i.e. `moduleID-elementID`), JS gets mad, and we need to at least do a good job of documenting that, since there's no expectation that users should know the internals of how namespacing works (but in this case, this obviously becomes relevant). You'd think that then, it would be enough to do this:\r\n\r\n```r\r\nconditionalPanel(\r\n  condition = paste0(\"input['\", ns(\"smooth\"), \"'] == true\"),\r\n   ...\r\n)\r\n```\r\n\r\nBut unfortunately that is impossible because:\r\n\r\n2. `ns` is doing something weird. If you inspect the HTML, instead of seeing something like this:\r\n\r\n```html\r\n<div data-display-if=\"input['cp-smooth'] == true\" style=\"display: none;\">\r\n```\r\n\r\nYou see this:\r\n\r\n```html\r\n<div data-display-if=\"input.cp-function (x, kind = c(&quot;3RS3R&quot;, &quot;3RSS&quot;, &quot;3RSR&quot;, &quot;3R&quot;, &quot;3&quot;, &quot;S&quot;), twiceit = FALSE, endrule = c(&quot;Tukey&quot;, &quot;copy&quot;), do.ends = FALSE) \r\n{\r\n    if (!is.numeric(x)) \r\n        stop(&quot;attempt to smooth non-numeric values&quot;)\r\n    if (anyNA(x)) \r\n        stop(&quot;attempt to smooth NA values&quot;)\r\n    endrule <- match.arg(endrule)\r\n    rules <- c(&quot;copy&quot;, &quot;Tukey&quot;)\r\n    if (is.na(iend <- pmatch(endrule, rules))) \r\n        stop(&quot;invalid 'endrule' argument&quot;)\r\n    kind <- match.arg(kind)\r\n    if (substr(kind, 1, 3) == &quot;3RS&quot; &amp;&amp; !do.ends) \r\n        iend <- -iend\r\n    else if (kind == &quot;S&quot;) \r\n        iend <- as.logical(do.ends)\r\n    type <- match(kind, c(&quot;3RS3R&quot;, &quot;3RSS&quot;, &quot;3RSR&quot;, &quot;3R&quot;, &quot;3&quot;, &quot;S&quot;))\r\n    smo <- .Call(C_Rsm, as.double(x), type, iend)\r\n    if (twiceit) {\r\n        r <- smooth(x - smo$y, kind = kind, twiceit = FALSE, endrule = endrule, do.ends = do.ends)\r\n        smo$y <- smo$y + r\r\n        if (!is.null(smo$iter)) \r\n            smo$iter <- smo$iter + attr(r, &quot;iter&quot;)\r\n        if (!is.null(smo$changed)) \r\n            smo$changed <- smo$changed || attr(r, &quot;changed&quot;)\r\n    }\r\n    if (is.ts(x)) \r\n        smo$y <- ts(smo$y, start = start(x), frequency = frequency(x))\r\n    structure(smo$y, kind = kind, twiced = twiceit, iter = smo$iter, changed = smo$changed, endrule = if (substr(kind, 1, 1) == &quot;3&quot;) \r\n        rules[iend], call = match.call(), class = c(&quot;tukeysmooth&quot;, if (is.ts(x)) &quot;ts&quot;))\r\n} == true\">\r\n```\r\n\r\nI don't really understand how `ns` is doing this, but it's clear it is coming from that, since simple pasting works fine. Which brings us to the only way that you can reliably work with conditional panels and modules, as of now:\r\n\r\n**Only working solution right now**\r\n```r\r\nconditionalPanel(\r\n  condition = paste0(\"input['\", id, \"-smooth'] == true\"),\r\n  ...\r\n)\r\n```\r\n\r\nWhich is not really ideal..."}}
{"actor":{"display_login":"bborgesr"}}