【发布时间】:2021-01-26 19:26:11
【问题描述】:
我有两个问题:
我在数据库中有两个依赖过滤器,我想按玩家或他们的 ID 进行搜索。我还希望第一个过滤器 (SelectInput) 能够响应。
例如,如果我在 ID 中输入数字 2,我希望我的 selectInput 自动显示 Lionel Messi。
这是代码,感谢您的回答
library(DT)
library(shinydashboard)
library(shiny)
library(shinyWidgets)
library(dplyr)
Database<- data.frame(Player=c("Cristiano Ronaldo","Lionel Messi","Neymar Jr","Cristiano Ronaldo"),ID=c(1,2,3,1))
ui<-dashboardPage(title="Application",skin="red",
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
selectInput("player",HTML('Please select your player'),choices=names(table(Database$Player))),
searchInput(inputId = "IDSEARCH", label = HTML('Or Please write the ID player'),
#placeholder = "13850",
btnSearch = icon("search"),
btnReset = icon("remove"),
width = "500px"),
DT::dataTableOutput("mtable2")
))
server <- function(input, output){
mtable2 <- reactive({filter(Database,(Player==input$player|ID==input$IDSEARCH))})
output$mtable2<-DT::renderDataTable({DT::datatable(mtable2())})
}
shinyApp(ui,server)
【问题讨论】:
-
你指定了所有相关的包吗?我怀疑您至少缺少
dplyr和shinyWidgets? -
谢谢,我修改了
标签: r filter shiny shinydashboard flexdashboard