R Shiny - extendShinyjs 错误解析提供的 JavaScript 代码

R Shiny - extendShinyjs Error parsing the JavaScript code provided

我正在测试 extendShinyJs 并在 GitHub 上进行简单测试:link.

我已经安装了 V8 包,但是我得到了这个错误,即使是使用示例脚本也是如此: 错误:shinyjs:解析提供的 JavaScript 代码时出错。

我还尝试将 JavaScript 代码移动到 www 文件夹下的单独文件中。

当前会话的附加信息:

> sessionInfo()
R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

知道如何 运行 extendShinyjs 吗?

ui.R:

library(shiny)
library(shinyjs)
library(shinyAce)
#library(V8)

# Define UI for application that draws a histogram
shinyUI(fluidPage(

  shinyjs::useShinyjs(),


     extendShinyjs(text = "myfunc.js"),

       navbarPage("Tweets stuff",
tabPanel("Contact",
       sidebarLayout(
         sidebarPanel(
           textInput("ctFrom", "From:", value=""),
           textInput("ctSubject", "Subject:", value="Sugerencias BTT"),
           actionButton("ctSend", "Send")
         ),
         mainPanel(
           aceEditor("ctMessage", value="")
         )
       )
    ))
)

)

myfunc.js (in www folder):

    shinyjs.pageCol = function(params){
      $('body').css('background', params);
    };

server.R:

shinyServer(function(input, output, session) {
  #Programming with Twitter API

  observeEvent(input$ctSend, {
    #I have more things here
    js$pageCol (input$ctSend)
  })
}

如果您认为需要查看更多代码,请问我。 我想清除"aceEditor"里面的文字。

感谢您的快速帮助。

我可以 运行 你的例子(但为了简单起见,我把 JS 代码变成了一个字符串而不是它自己的文件。如果你想让它在一个文件中,你需要使用 file = 正如我在评论中所说的参数。

为了证明 JS 有效,我将 JS 函数从 "changing the background" 更改为简单地打印按钮的值。让我知道这个确切的代码是否产生了错误:

library(shiny)
library(shinyjs)
library(shinyAce)

jscode <- "    shinyjs.pageCol = function(params){
      alert(params);
    };"

runApp(shinyApp(
  ui = fluidPage(
    shinyjs::useShinyjs(),


    extendShinyjs(text = jscode),

    navbarPage("Tweets stuff",
               tabPanel("Contact",
                        sidebarLayout(
                          sidebarPanel(
                            textInput("ctFrom", "From:", value=""),
                            textInput("ctSubject", "Subject:", value="Sugerencias BTT"),
                            actionButton("ctSend", "Send")
                          ),
                          mainPanel(
                            aceEditor("ctMessage", value="")
                          )
                        )
               ))
  ),
  server = function(input, output, session) {
    observeEvent(input$ctSend, {
      #I have more things here
      js$pageCol (input$ctSend)
    })
  }
))