问题描述
我正在尝试制作一个搜索栏,以允许用户从显示我的 Mongodb 数据库中的值的表中搜索任何值。
首先我想在一个表中显示所有值(我使用data1),然后在同一个表中我想执行搜索并显示搜索值所在的行
但我无法执行任何搜索,因为我觉得缺少某些东西
我的代码如下:
library(shiny)
library(shinySearchbar)
library(shinyWidgets)
library(mongolite)
mongo_database <- "Test"
mongo_collection <- "Test1"
url_path = sprintf("mongodb+srv://...)
shinyApp(
ui <- fluidPage(
titlePanel("BoQ Data"),sidebarLayout(
sidebarPanel(
selectInput("id","PLEASE SELECT :",choices =c("All","Title","Instruction","ITEMS","rate"),selected = "All"),actionButton("update","Load"),hr(),#tags$h4("Search Input"),searchInput(
inputId = "search",label = "Enter your text",placeholder = "A placeholder",btnSearch = icon("search"),btnReset = icon("remove"),width = "450px"
)
),mainPanel(
tableOutput("mydata"),verbatimtextoutput("res")
)
)
),server <- function(input,output,session) {
data1 <- eventReactive(input$update,{
mon <- mongo(collection = mongo_collection,db = mongo_database,url = url_path,verbose = TRUE)
switch(input$id,"All" = 'All',"Title" = 'Title',"Instruction" = 'Instruction',"ITEMS" = 'ITEMS',"rate" = 'rate'
)
switch (input$id,All = mon$find(query = '{}'),Title = mon$find(query ='{}',fields = '{"Title" : 1,"field1":1,"_id":0}'),Instruction = mon$find(query ='{}',fields = '{"Instruction" : 1,"field2":1,ITEMS = mon$find(query ='{}',fields = '{"ITEMS" : 1,"field3":1,rate = mon$find(query ='{}',fields = '{"rate" : 1,"field4":1,"_id":0}')
)
#rm(mon)
},ignoreNULL = FALSE)
#output$mydata <- renderDataTable({
output$mydata <- renderTable({
data1()
#Data1
})
output$res <- renderPrint({
input$search
})
}
)
shinyApp(ui,server)
谁能帮忙制作搜索栏?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)