R语言 如何创建一个有层次过滤选项的闪亮应用程序

5f0d552i  于 2023-01-03  发布在  其他
关注(0)|答案(1)|浏览(169)

mydataset的子集

mydata<-
        
structure(list(Country = c("belgium", "france", "brazil", "chile", 
"england", "germany", "france", "europe", "germany", "england", 
"germany", "colombia", "england", "argentina", "europe", "japan", 
"germany", "england", "europe", "spain", "europe", "spain", "spain", 
"europe", "netherlands", "spain", "belgium", "france", "france", 
"france", "germany", "france", "netherlands", "south", "germany", 
"belgium", "germany", "france", "spain", "spain", "europe", "france", 
"spain", "spain", "england", "italy", "brazil", "france", "england", 
"europe", "england", "paraguay", "argentina", "colombia", "europe", 
"colombia", "germany", "france", "argentina", "france", "uruguay", 
"europe", "europe", "belgium", "france", "europe", "argentina", 
"spain", "france", "france", "france", "germany", "europe", "france", 
"japan", "spain", "france", "germany", "netherlands", "argentina", 
"belgium", "japan", "england", "england", "belgium", "uruguay", 
"england", "japan", "belgium", "england", "france", "italy", 
"germany", "england", "germany", "chile", "chile", "england", 
"portugal", "brazil", "europe", "england", "europe", "france", 
"colombia", "france", "italy", "italy", "south", "uruguay", "germany", 
"europe", "germany", "france", "belgium", "spain", "brazil", 
"netherlands", "italy", "france", "europe", "colombia", "france", 
"argentina", "colombia", "argentina", "portugal", "italy", "england", 
"colombia", "england", "england", "europe", "france", "china", 
"argentina", "germany", "belgium", "uruguay", "england", "portugal", 
"argentina", "italy", "france", "netherlands", "france", "chile", 
"belgium", "france", "france", "netherlands", "england", "argentina", 
"france", "france", "england", "italy", "france", "italy", "portugal", 
"europe", "brazil", "brazil", "argentina", "colombia", "spain", 
"spain", "south", "spain", "france", "germany", "france", "spain", 
"italy", "europe", "germany", "uruguay", "italy", "france", "france", 
"belgium", "spain", "france", "italy", "germany", "france", "colombia", 
"germany", "belgium", "argentina", "south", "netherlands", "germany", 
"germany", "colombia", "spain", "spain", "europe", "france", 
"south"), League = c("pro-league", "ligue-1", "serie-a", "primera-division", 
"premier-league", "bundesliga", "coupe-de-france", "uefa-womens-champions-league", 
"bundesliga", "championship", "2-bundesliga", "categoria-primera-a", 
"championship", "primera-division", "uefa-champions-league", 
"j1-league", "2-bundesliga", "premier-league", "uefa-champions-league", 
"segunda-division", "uefa-womens-champions-league", "segunda-division", 
"segunda-division", "uefa-womens-champions-league", "eredivisie", 
"segunda-division", "pro-league", "ligue-1", "ligue-1", "ligue-1", 
"2-bundesliga", "ligue-1", "eredivisie", "america-copa-libertadores", 
"2-bundesliga", "pro-league", "2-bundesliga", "ligue-1", "segunda-division", 
"la-liga", "uefa-womens-champions-league", "ligue-1", "segunda-division", 
"segunda-division", "championship", "serie-b", "serie-a", "coupe-de-france", 
"league-cup", "uefa-champions-league", "championship", "division-profesional", 
"primera-division", "categoria-primera-a", "uefa-womens-champions-league", 
"categoria-primera-a", "bundesliga", "ligue-1", "primera-division", 
"ligue-2", "primera-division", "uefa-champions-league", "uefa-champions-league", 
"pro-league", "ligue-2", "uefa-womens-champions-league", "primera-division", 
"segunda-division", "ligue-1", "ligue-1", "ligue-2", "bundesliga", 
"uefa-womens-champions-league", "ligue-1", "j1-league", "la-liga", 
"ligue-1", "2-bundesliga", "eredivisie", "primera-division", 
"pro-league", "j1-league", "championship", "championship", "pro-league", 
"primera-division", "championship", "j1-league", "pro-league", 
"premier-league", "ligue-1", "serie-a", "bundesliga", "championship", 
"bundesliga", "primera-division", "primera-division", "championship", 
"liga-nos", "serie-a", "uefa-champions-league", "championship", 
"uefa-champions-league", "coupe-de-france", "categoria-primera-a", 
"ligue-1", "coppa-italia", "serie-b", "america-copa-libertadores", 
"primera-division", "bundesliga", "uefa-champions-league", "2-bundesliga", 
"ligue-2", "pro-league", "segunda-division", "serie-a", "eredivisie", 
"serie-a", "ligue-1", "uefa-champions-league", "categoria-primera-a", 
"ligue-1", "primera-division", "categoria-primera-a", "primera-division", 
"liga-nos", "serie-b", "championship", "categoria-primera-a", 
"premier-league", "championship", "uefa-womens-champions-league", 
"coupe-de-france", "chinese-super-league", "primera-division", 
"bundesliga", "pro-league", "primera-division", "championship", 
"liga-nos", "primera-division", "serie-b", "coupe-de-france", 
"eredivisie", "ligue-1", "primera-division", "pro-league", "ligue-1", 
"ligue-1", "eredivisie", "championship", "primera-division", 
"ligue-1", "ligue-1", "premier-league", "serie-b", "ligue-1", 
"serie-a", "liga-nos", "uefa-womens-champions-league", "serie-a", 
"serie-a", "primera-division", "categoria-primera-a", "segunda-division", 
"segunda-division", "america-copa-libertadores", "segunda-division", 
"ligue-1", "bundesliga", "ligue-1", "la-liga", "serie-b", "uefa-womens-champions-league", 
"bundesliga", "primera-division", "serie-a", "ligue-1", "coupe-de-france", 
"pro-league", "segunda-division", "ligue-1", "serie-a", "bundesliga", 
"ligue-1", "categoria-primera-a", "2-bundesliga", "pro-league", 
"primera-division", "america-copa-libertadores", "eredivisie", 
"2-bundesliga", "dfb-pokal", "categoria-primera-a", "segunda-division", 
"la-liga", "uefa-womens-champions-league", "ligue-2", "america-copa-libertadores"
), Year = c("2021", "2020", "2022", "2022", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2022", "2021", "2022", "2021", 
"2022", "2021", "2021", "2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2020", "2021", "2020", "2021", 
"2020", "2021", "2022", "2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2022", 
"2021", "2021", "2021", "2021", "2022", "2022", "2022", "2021", 
"2022", "2021", "2021", "2022", "2021", "2022", "2021", "2021", 
"2021", "2021", "2021", "2022", "2021", "2020", "2021", "2021", 
"2021", "2021", "2020", "2022", "2021", "2021", "2021", "2021", 
"2022", "2021", "2022", "2021", "2021", "2021", "2022", "2021", 
"2022", "2021", "2021", "2020", "2021", "2021", "2021", "2021", 
"2022", "2022", "2021", "2021", "2022", "2021", "2021", "2021", 
"2021", "2022", "2021", "2021", "2021", "2022", "2022", "2021", 
"2021", "2021", "2021", "2021", "2021", "2022", "2021", "2021", 
"2021", "2021", "2022", "2021", "2022", "2022", "2022", "2021", 
"2021", "2021", "2022", "2021", "2021", "2021", "2021", "2022", 
"2022", "2021", "2021", "2022", "2021", "2021", "2022", "2021", 
"2021", "2021", "2021", "2022", "2021", "2021", "2020", "2021", 
"2021", "2022", "2021", "2020", "2021", "2021", "2021", "2021", 
"2021", "2021", "2022", "2022", "2022", "2022", "2021", "2021", 
"2022", "2021", "2021", "2021", "2021", "2021", "2021", "2021", 
"2021", "2022", "2021", "2020", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2022", "2021", "2021", "2022", "2022", 
"2021", "2021", "2021", "2022", "2021", "2021", "2021", "2021", 
"2022"), Club = c("Sint-Truiden", "Reims", "Coritiba", "Ñublense", 
"Chelsea", "Eintracht Frankfurt", "Chusclan-Laudun-l'Ardois", 
"Skiljebo U19", "Stuttgart", "Bristol City", "Hansa Rostock", 
"Envigado", "Reading", "Arsenal de Sarandí", "Real Madrid", "Sanfrecce Hiroshima", 
"Heidenheim", "Everton", "RB Leipzig", "Almería", "Chelsea Women", 
"Burgos CF", "CD Lugo", "Malmö FF U19", "Heerenveen", "Leganés", 
"RSC Anderlecht", "Rennes", "Reims", "Montpellier", "Paderborn", 
"Brest", "Heracles", "Atlético Mineiro", "Dynamo Dresden", "Sporting Charleroi", 
"Nürnberg", "Olympique Marseille", "Burgos CF", "Deportivo Alavés", 
"Öster U19", "Olympique Marseille", "SD Ponferradina", "Real Zaragoza", 
"Peterborough United", "SPAL", "Juventude", "Illzach Modenheim", 
"Mansfield Town", "Villarreal", "West Bromwich Albion", "Olimpia", 
"Boca Juniors", "Deportivo Pereira", "Brommapojkarna U19", "Unión Magdalena", 
"Bayern München", "Montpellier", "Central Córdoba SdE", "Caen", 
"Nacional", "Dinamo Tbilisi", "Inter Milan", "Sint-Truiden", 
"Caen", "Landskrona BoIS U19", "Defensa y Justicia", "SD Ponferradina", 
"Rennes", "Strasbourg", "Valenciennes", "Bochum", "Halmstad U19", 
"Lorient", "Yokohama F. Marinos", "Real Sociedad", "Montpellier", 
"Heidenheim", "Heracles", "Racing Club", "Royal Antwerp FC", 
"Nagoya Grampus", "Blackburn Rovers", "Millwall", "Sint-Truiden", 
"Fénix", "Peterborough United", "Shimizu S-Pulse", "Sporting Charleroi", 
"Liverpool", "Lorient", "AC Milan", "Borussia M'gladbach", "Blackburn Rovers", 
"RB Leipzig", "Curicó Unido", "Universidad Católica", "Cardiff City", 
"Benfica", "Fluminense", "Club Brugge", "Bristol City", "Ajax", 
"Créteil", "Millonarios", "Lorient", "Venezia", "Lecce", "Talleres Córdoba", 
"Fénix", "Eintracht Frankfurt", "Atalanta", "Heidenheim", "Grenoble Foot 38", 
"RFC Seraing", "SD Amorebieta", "Ceará", "NEC", "Cagliari", "Lille", 
"Ferencváros", "Deportivo Pereira", "Saint-Étienne", "Racing Club", 
"Deportes Tolima", "Boca Juniors", "Paços de Ferreira", "Perugia", 
"Coventry City", "Jaguares de Córdoba", "Aston Villa", "Swansea City", 
"GAIS U19", "Schiltigheim", "Hebei CFFC", "Lanús", "Bayer Leverkusen", 
"Royal Antwerp FC", "Albion", "Hull City", "FC Arouca", "Platense", 
"Pisa", "Red Star", "Ajax", "Lille", "O'Higgins", "Club Brugge", 
"Lens", "Olympique Marseille", "Go Ahead Eagles", "Birmingham City", 
"Central Córdoba SdE", "Clermont", "Metz", "Wolverhampton Wanderers", 
"Brescia", "Troyes", "Cagliari", "Sporting Braga", "Hammarby U19", 
"Fortaleza", "Coritiba", "Sarmiento", "Once Caldas", "AD Alcorcón", 
"CD Tenerife", "Flamengo", "Mirandés", "Olympique Lyonnais", 
"Hertha BSC", "Lens", "Deportivo Alavés", "Parma", "Kalmar U19", 
"Augsburg", "Torque", "Sassuolo", "Bordeaux", "Molsheim Ernolsheim", 
"Union Saint-Gilloise", "Real Zaragoza", "Saint-Étienne", "Cagliari", 
"Eintracht Frankfurt", "Saint-Étienne", "Millonarios", "Ingolstadt", 
"KV Mechelen", "Banfield", "Libertad", "Fortuna Sittard", "Holstein Kiel", 
"Stuttgart", "La Equidad", "SD Amorebieta", "Rayo Vallecano", 
"Syrianska U19", "Pau", "Caracas"), total_goal_count = c(4L, 
0L, 4L, 2L, 7L, 2L, 3L, 7L, 5L, 5L, 3L, 0L, 2L, 2L, 4L, 3L, 0L, 
5L, 3L, 0L, 1L, 4L, 1L, 1L, 4L, 1L, 2L, 3L, 2L, 3L, 3L, 1L, 2L, 
1L, 3L, 1L, 4L, 4L, 3L, 5L, 1L, 2L, 3L, 2L, 4L, 2L, 3L, 2L, 3L, 
2L, 3L, 5L, 1L, 2L, 4L, 0L, 4L, 2L, 6L, 1L, 2L, 3L, 2L, 3L, 4L, 
1L, 3L, 5L, 1L, 2L, 1L, 4L, 1L, 3L, 4L, 1L, 0L, 2L, 2L, 2L, 4L, 
1L, 0L, 1L, 3L, 1L, 4L, 2L, 4L, 1L, 3L, 0L, 2L, 1L, 4L, 4L, 3L, 
3L, 2L, 4L, 6L, 5L, 1L, 3L, 1L, 0L, 4L, 4L, 1L, 1L, 2L, 5L, 3L, 
2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 3L, 5L, 5L, 2L, 8L, 2L, 1L, 1L, 
3L, 2L, 0L, 4L, 2L, 3L, 1L, 3L, 4L, 4L, 4L, 6L, 2L, 3L, 2L, 3L, 
2L, 2L, 0L, 2L, 4L, 5L, 3L, 4L, 4L, 3L, 3L, 2L, 2L, 4L, 1L, 2L, 
2L, 1L, 3L, 4L, 1L, 0L, 3L, 2L, 6L, 1L, 1L, 3L, 2L, 4L, 2L, 2L, 
4L, 3L, 2L, 1L, 2L, 2L, 2L, 3L, 4L, 0L, 2L, 3L, 2L, 5L, 4L, 3L, 
2L, 2L, 1L, 2L, 2L, 5L, 0L)), row.names = c(NA, -200L), class = c("tbl_df", 
"tbl", "data.frame"))

我闪亮的建筑:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  
  dashboardHeader(title = "FOOTBAL ANALYTICS",titleWidth = 1000),
  dashboardSidebar(
    
    sidebarMenu(
      
      selectInput("Country_id","Country", choices = LETTERS),
      selectInput("League_id","league",choices = LETTERS),
      selectInput("Club_id","Club",choices = LETTERS),
      
      menuItem("Offensive statistics",
               menuSubItem("Menu 1.1"),
               menuSubItem("Menu 1.2")
        
      ),
      
      menuItem("Defensive statistics",
               menuSubItem("Menu 2.1"),
               menuSubItem("Menu 2.2")
        
      ),
      
      menuItem("Overall statistics",
               menuSubItem("Menu 3.1"),
               menuSubItem("Menu 3.2")
        
      )
      
      
    )
  ),
  dashboardBody()
  
  
  
)



server <- function(input, output, session) {
  
  
  
}

shinyApp(ui, server)

我的目标是分层和优化过滤,让我的“闪亮”运行得更快。我的数据库非常大,几乎有一百万行,如果不是更多的话。
我们的目标是首先过滤国家,一旦国家被过滤,联赛的过滤单元格将只显示这个国家的联赛,我可以选择这个国家的一个联赛,一旦这个联赛被选择,我可以只选择这个联赛的俱乐部,并只过滤这个俱乐部的数据。所以我们有一个过滤层次国家-联赛-俱乐部。
例如,我想过滤france,然后过滤league-1,最后过滤Montpellier
通常情况下,如果我决定过滤器上france,联赛:bundesliga不应显示在对联赛进行过滤的单元格中。

Translated with www.DeepL.com/Translator (free version)
gt0wga4j

gt0wga4j1#

您可以组合使用renderUIuiOutput,以便在服务器端动态地执行此操作。

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "FOOTBAL ANALYTICS",titleWidth = 1000),
  dashboardSidebar(
    sidebarMenu(
      uiOutput('dd1'), 
      uiOutput('dd2'), 
      uiOutput('dd3'), 
      menuItem("Offensive statistics",
               menuSubItem("Menu 1.1"),
               menuSubItem("Menu 1.2")
      ),
      menuItem("Defensive statistics",
               menuSubItem("Menu 2.1"),
               menuSubItem("Menu 2.2")
      ),
      menuItem("Overall statistics",
               menuSubItem("Menu 3.1"),
               menuSubItem("Menu 3.2")
      )
    )
  ),
  dashboardBody(
    tableOutput("data")
  )
)

server <- function(input, output, session) {
  output$dd1 <- renderUI({
    selectInput("Country_id","Country", choices = mydata$Country) 
  })
  
  output$dd2 <- renderUI({
    req(input$Country_id)
    selectInput("League_id","league",choices = mydata$League[mydata$Country == input$Country_id])
  })
  
  output$dd3 <- renderUI({
    req(input$League_id)
    selectInput("Club_id","Club",choices = mydata$Club[mydata$Country == input$Country_id & mydata$League == input$League_id])
  })
  
  output$data <- renderTable({
    req(input$Club_id)
    subset(mydata, Country == input$Country_id & League == input$League_id & Club == input$Club_id)
  })

}

shinyApp(ui, server)

相关问题