【问题标题】:JSON Parse Error in MongoDB and RMongoDB 和 R 中的 JSON 解析错误
【发布时间】:2014-07-15 20:36:32
【问题描述】:

我是 R 和 MongoDB 以及与编程相关的一切的新手,所以请多多包涵。我正在尝试根据用户输入(下拉菜单)查询 MongoDB 数据库。当我运行代码时,我收到以下错误:

Error: com.mongodb.util.JSONParseException: 
       {'Name':input$prod}
               ^

这是我的用户界面:

mydb <- mongoDbConnect("mysearch")

shinyUI(fluidPage(
    titlePanel("MYsearch"),
    sidebarPanel(
        selectInput("prod", label = "Choose my Product/Service", 
        choices = list("Engineering", "Operations",
                       "Detection"), selected = "Engineering")
    ),
    mainPanel(tableOutput("table1"))
    )
))

这是我的服务器:

my <- mongoDbConnect("mysearch")

shinyServer(function(input, output) {
    output$table1 <- renderTable({ 
          dbGetQuery(mydb, "usercollection", "{'Name':input$prod}")
     })
}
)

非常感谢您的帮助。

【问题讨论】:

    标签: r mongodb shiny rmongo


    【解决方案1】:

    试试这个...

    queryParam <- paste('{\'Name\':', input$prod, '}');
    
    shinyServer(function(input, output) {
        output$table1 <- renderTable({ 
              dbGetQuery(mydb, "usercollection", queryParam)
         })
    }
    )
    

    您将字符串“input$prod”传递给函数,而不是传递存储在 input$prod 中的值。

    【讨论】:

      猜你喜欢
      • 2016-05-18
      • 1970-01-01
      • 1970-01-01
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-22
      • 1970-01-01
      相关资源
      最近更新 更多