【发布时间】:2018-10-06 14:57:43
【问题描述】:
library(shiny)
library(mongolite)
ui <- fluidPage(
titlePanel("Mongodb Data"),
sidebarLayout(
sidebarPanel(
textInput("_id", "Document type:", "")
),
mainPanel(
dataTableOutput("mydata")
)
)
)
server <- function(input, output) {
mon <- mongo(collection = "collectionname", db = "db name", url = "mongodb://localhost:27017")
output$mydata <- renderDataTable({
doc_type <- paste0(doc_type= input$doc_id)
mon$find( query = '{"doc_type" : {"$in" : ["x", "y"]} }' , limit = 100)
})
}
}
警告:错误,如果没有活动的反应上下文,则不允许操作。 (你试图做一些只能在反应式表达式或观察者内部完成的事情。)
如何添加响应式查询并从 MongoDB 集合中的特定列检索数据?每当我给文本输入值 x 或 y 时,它都应该显示来自 MongoDB 数据库的相关文档。
【问题讨论】:
-
您拥有
textInput("_id",...),但随后拥有input$doc_id。这是“_id”与“doc_id”不同的错字吗? -
是的,这是一个拼写错误。我很抱歉这个错误。 @MrFlick