闪光和Javascript -未捕获的参考错误:TRUE没有定义。

时间:2022-11-07 08:52:06

I have a shinyapp which has a basic login screen.

我有一个shinyapp,它有一个基本的登录界面。

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:

当应用程序加载时,“日志”变量为FALSE。当用户在会话中成功登录时,R登录代码如下:

X$Logged <- TRUE

At this point, in the javascript console I get warnings saying "Uncaught ReferenceError: TRUE is not defined".

此时,在javascript控制台中,我得到警告说“未捕获的ReferenceError: TRUE未定义”。

I click on the link to go to the code, and the javascript code is:

点击链接进入代码,javascript代码为:

(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".

我是一个初学者。我假设,首先,这是我上面R代码的javascript呈现,其次,它不喜欢它,因为javascript需要一个小写的布尔值“true”。

How can I get around this? Equally, R doesn't like lower case boolean.

我怎样才能避开这个问题呢?同样,R不喜欢小写布尔。

2 个解决方案

#1


1  

How can I get around this? Equally, R doesn't like lower case boolean.

我怎样才能避开这个问题呢?同样,R不喜欢小写布尔。

Define one in the other, e.g. as you're going to JavaScript, before your code (in the JavaScript)

在另一个中定义一个,例如,在编写代码之前(在JavaScript中)使用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.

或者,你也可以使用类似bool的东西,比如1和0。

Finally, how are you doing the R to JS transformation? This well may be a bug in the framework you've used

最后,如何做R到JS的变换?这可能是您所使用的框架中的一个bug。

#2


0  

Paul's and Mritunjay's answer helped me to get this fixed.

Paul和Mritunjay的回答帮我解决了这个问题。

The misunderstanding was in a conditionalPanel() within my ui.R file. I had:

这个误解出现在我的ui的一个conditionalPanel()中。R文件。我有:

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:

我发现了单个的“=”而不是“=”,并意识到在引号内的条件是JS,而不是r。因此我改变了我的ui。R:

conditionalPanel(
condition="X$Logged=true"
...
)

However, I kept upper case "TRUE" in all of my server.R logic, like this:

但是,我在所有服务器上都保留大写的“TRUE”。R逻辑,像这样:

X$Logged <- TRUE

...and it now works.

…和现在的作品。

#1


1  

How can I get around this? Equally, R doesn't like lower case boolean.

我怎样才能避开这个问题呢?同样,R不喜欢小写布尔。

Define one in the other, e.g. as you're going to JavaScript, before your code (in the JavaScript)

在另一个中定义一个,例如,在编写代码之前(在JavaScript中)使用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.

或者,你也可以使用类似bool的东西,比如1和0。

Finally, how are you doing the R to JS transformation? This well may be a bug in the framework you've used

最后,如何做R到JS的变换?这可能是您所使用的框架中的一个bug。

#2


0  

Paul's and Mritunjay's answer helped me to get this fixed.

Paul和Mritunjay的回答帮我解决了这个问题。

The misunderstanding was in a conditionalPanel() within my ui.R file. I had:

这个误解出现在我的ui的一个conditionalPanel()中。R文件。我有:

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:

我发现了单个的“=”而不是“=”,并意识到在引号内的条件是JS,而不是r。因此我改变了我的ui。R:

conditionalPanel(
condition="X$Logged=true"
...
)

However, I kept upper case "TRUE" in all of my server.R logic, like this:

但是,我在所有服务器上都保留大写的“TRUE”。R逻辑,像这样:

X$Logged <- TRUE

...and it now works.

…和现在的作品。