Reputation: 642
I have a shinyapp which has a basic login screen.
When the app loads, the "Logged" variable is FALSE. When the user successfully logs in within the session, the R login code is as follows:
X$Logged <- TRUE
At this point, in the javascript console I get warnings saying "Uncaught ReferenceError: TRUE is not defined".
I click on the link to go to the code, and the javascript code is:
(function() {
with (this) {return (X$Logged=TRUE);}
})
I am a beginner. I am assuming that firstly, this is the javascript render of my R code above, and secondly that it doesn't like it because javascript expects a lower case boolean "true".
How can I get around this? Equally, R doesn't like lower case boolean.
Upvotes: 3
Views: 4261
Reputation: 642
Paul's and Mritunjay's answer helped me to get this fixed.
The misunderstanding was in a conditionalPanel() within my ui.R file. I had:
conditionalPanel(
condition="X$Logged=TRUE"
...
)
I spotted the single "=" instead of "==" and realised the condition within the inverted commas is JS, and not R. I therefore changed my ui.R to this:
conditionalPanel(
condition="X$Logged=true"
...
)
However, I kept upper case "TRUE" in all of my server.R logic, like this:
X$Logged <- TRUE
...and it now works.
Upvotes: 1
Reputation: 66334
How can I get around this? Equally, R doesn't like lower case boolean.
Define one in the other, e.g. as you're going to JavaScript, before your code (in the JavaScript)
var TRUE = true, FALSE = false;
Then
(function() {
with (this) {return (X$Logged=TRUE);} // should now work
})
Alternatively, you could use bool-like things, i.e. 1
and 0
instead.
Finally, how are you doing the R to JS transformation? This well may be a bug in the framework you've used
Upvotes: 2