AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / coding / Perguntas / 78801413
Accepted
firmo23
firmo23
Asked: 2024-07-27 20:41:03 +0800 CST2024-07-27 20:41:03 +0800 CST 2024-07-27 20:41:03 +0800 CST

Desative o actionButton com base na seleção de entrada dos widgets brilhantes

  • 772

Eu tenho o aplicativo brilhante abaixo e quero:

1.Quando o aplicativo é carregado pela primeira vez, os widgets não devem ter seleções e os botões de ação devem estar desativados.

2.Quando um distrito for selecionado, atualize as opções de escola.

3.Ative o botão de ação "Visualizar" quando pelo menos uma escola for selecionada.

4.Ative o botão de ação "Download" somente após clicar em "Visualizar".

5.Se todas as seleções forem desmarcadas, ambos os botões de ação deverão ser desativados novamente.

Fiz todos eles funcionarem, exceto que o botão Visualizar é inicialmente ativado e, se todas as seleções forem desmarcadas, o botão Visualizar é desativado novamente.

library(renv)
# library(AzureRMR)
# library(AzureStor)
#source(here::here("code/functions/momentmn_functions.R"))
library(dplyr)
library(shiny)
library(shinyWidgets)
library(DT)
library(tidyr)

early <- structure(list(district_name = c("Nonpublic School", "Nonpublic School", 
                                          "Nonpublic School", "Nonpublic School", "Nonpublic School", "Nonpublic School", 
                                          "Nonpublic School", "Nonpublic School", "Nonpublic School", "Nonpublic School", 
                                          "Nonpublic School", "Nonpublic School", "Nonpublic School", "Nonpublic School", 
                                          "Nonpublic School", "Nonpublic School", "Nonpublic School", "Nonpublic School", 
                                          "Nonpublic School", "Nonpublic School", "Nonpublic School", "Nonpublic School", 
                                          "Nonpublic School", "Nonpublic School", "Nonpublic School", "Nonpublic School", 
                                          "Nonpublic School", "Aitkin Public School District", "Minneapolis Public School Dist.", 
                                          "Minneapolis Public School Dist."), school_name_unique = c("Ascension Catholic School 0001-33-012", 
                                                                                                     "Risen Christ 0001-33-015", "St. Helena Catholic School 0001-33-036", 
                                                                                                     "Al-Amal School 0014-31-006", "St. Mary's Mission 0038-31-001", 
                                                                                                     "St. Joseph 0110-31-001", "Immanuel Lutheran School 0113-31-100", 
                                                                                                     "St. Joseph's Catholic 0196-31-007", "St. John The Baptist 0200-31-002", 
                                                                                                     "Our Lady Of Grace 0273-31-007", "St. Henry 0549-31-001", "St. Paul's Lutheran 0549-31-002", 
                                                                                                     "Talmud Torah 0625-31-879", "St. Dominic School 0659-31-012", 
                                                                                                     "Hills Christian 0671-31-001", "St. Paul's Lutheran 0719-31-003", 
                                                                                                     "St. Elizabeth Ann Seton School 0742-31-020", "Prince Of Peace Lutheran School 0742-31-022", 
                                                                                                     "St. Francis Xavier 0748-31-001", "Community Christian 0912-31-001", 
                                                                                                     "Fond Du Lac Ojibwe School 1094-34-030", "Bug-O-Nay-Ge-Shig 1115-34-010", 
                                                                                                     "Circle Of Life 1435-34-010", "Nay-Ah-Shing 1480-34-010", "Sacred Heart Area School 2170-31-001", 
                                                                                                     "St. Anne's 2397-31-001", "St. Mary Of Mt. Carmel 2753-31-002", 
                                                                                                     "Rippleside Elementary 0001-01-002", "Armatage Elementary 0001-03-103", 
                                                                                                     "Lake Harriet Lower Elementary 0001-03-104")), row.names = c(NA, 
                                                                                                                                                                  -30L), spec = structure(list(cols = list(temp_record_id = structure(list(), class = c("collector_character", 
                                                                                                                                                                                                                                                        "collector")), district_number = structure(list(), class = c("collector_character", 
                                                                                                                                                                                                                                                                                                                     "collector")), district_type = structure(list(), class = c("collector_character", 
                                                                                                                                                                                                                                                                                                                                                                                "collector")), school_number = structure(list(), class = c("collector_character", 
                                                                                                                                                                                                                                                                                                                                                                                                                                           "collector")), grade = structure(list(), class = c("collector_character", 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              "collector")), subject = structure(list(), class = c("collector_character", 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   "collector")), group_category = structure(list(), class = c("collector_character", 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               "collector")), student_group = structure(list(), class = c("collector_character", 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          "collector")), school_year = structure(list(), class = c("collector_double", 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   "collector")), denominator = structure(list(), class = c("collector_double", 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            "collector")), numerator = structure(list(), class = c("collector_double", 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   "collector"))), default = structure(list(), class = c("collector_guess", 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         "collector")), delim = ","), class = "col_spec"), class = c("spec_tbl_df", 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     "tbl_df", "tbl", "data.frame"))

all_districts <- unique(sort(early$district_name))
all_schools <- unique(sort(early$school_name_unique))

# Define UI for application that draws a histogram
ui <- fluidPage(
  
  # Application title
  titlePanel("EPC Civic Infrastructure Assessment File Prep"),
  
  # Sidebar with a slider input for number of bins 
  sidebarLayout(
    sidebarPanel(
      h2("Select Schools to Include"),
      shinyWidgets::pickerInput(inputId = "districts",
                                label = "Districts:",
                                choices = all_districts,
                                options = list(`actions-box` = TRUE),
                                multiple = TRUE),
      shinyWidgets::pickerInput(inputId = "schools",
                                label = "Schools:",
                                choices = "",
                                options = list(`actions-box` = TRUE),
                                selected = "",
                                multiple = TRUE),
      shiny::actionButton(inputId = "runButton", label = "Preview", disabled = TRUE),
      shiny::actionButton(inputId = "downButton", label = "Download", disabled = TRUE)),
    
    # Show a plot of the generated distribution
    mainPanel(
      dataTableOutput("early_reading")#,
      
    )
  )
)

# Define server logic required to draw a histogram
server <- function(input, output, session) {
  shiny::observeEvent(input$districts, {
    if(!is.null(input$districts) && length(input$districts) > 0){
      shinyWidgets::updatePickerInput(session = session, inputId = "schools",
                                      choices = early %>% dplyr::arrange(district_name, school_name_unique) %>% dplyr::filter(district_name %in% input$districts) %>% dplyr::select(school_name_unique) %>% unique() %>% pull())
    } else {
      shinyWidgets::updatePickerInput(session = session, inputId = "schools",
                                      choices = "",
                                      options = list(`actions-box` = TRUE),
                                      selected = "")
      shiny::updateActionButton(session, "runButton", disabled = TRUE)
      shiny::updateActionButton(session, "downButton", disabled = TRUE)
    }
  }, ignoreNULL = FALSE)
  
  shiny::observeEvent(input$schools, {
    if(!is.null(input$schools) && length(input$schools) > 0){
      shiny::updateActionButton(inputId = "runButton",
                                disabled = FALSE)
    } else {
      shiny::updateActionButton(inputId = "runButton",
                                disabled = TRUE)
      shiny::updateActionButton(inputId = "downButton",
                                disabled = TRUE)
    }
  }, ignoreNULL = FALSE)  
  
  shiny::observeEvent(input$runButton, {
    if(input$runButton > 0){
      shiny::updateActionButton(inputId = "downButton",
                                disabled = FALSE)
    }
  })
  
  output$early_reading <- renderDataTable({
    
    if(input$runButton == 0){return()}
    else{
      
      early <- early %>%
        dplyr::filter(district_name %in% input$districts, school_name_unique %in% input$schools)
      
      datatable(early)
      
    }
  })
}

# Run the application 
shinyApp(ui = ui, server = server)
  • 1 1 respostas
  • 24 Views

1 respostas

  • Voted
  1. Best Answer
    Jan
    2024-07-27T21:06:02+08:002024-07-27T21:06:02+08:00

    Você precisa de uma ifcondição adicional input$schools != ""se quiser que o botão 'Visualizar' seja desativado quando o aplicativo for carregado pela primeira vez. E se posteriormente as escolas forem limpas, o botão de visualização será desativado novamente. Da mesma forma, também deixo datatabledesaparecer se nenhuma escola for selecionada. Isso é implementado abaixo.

    library(renv)
    library(dplyr)
    library(shiny)
    library(shinyWidgets)
    library(DT)
    library(tidyr)
    
    early <-
      structure(
        list(
          district_name = c(
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Nonpublic School",
            "Aitkin Public School District",
            "Minneapolis Public School Dist.",
            "Minneapolis Public School Dist."
          ),
          school_name_unique = c(
            "Ascension Catholic School 0001-33-012",
            "Risen Christ 0001-33-015",
            "St. Helena Catholic School 0001-33-036",
            "Al-Amal School 0014-31-006",
            "St. Mary's Mission 0038-31-001",
            "St. Joseph 0110-31-001",
            "Immanuel Lutheran School 0113-31-100",
            "St. Joseph's Catholic 0196-31-007",
            "St. John The Baptist 0200-31-002",
            "Our Lady Of Grace 0273-31-007",
            "St. Henry 0549-31-001",
            "St. Paul's Lutheran 0549-31-002",
            "Talmud Torah 0625-31-879",
            "St. Dominic School 0659-31-012",
            "Hills Christian 0671-31-001",
            "St. Paul's Lutheran 0719-31-003",
            "St. Elizabeth Ann Seton School 0742-31-020",
            "Prince Of Peace Lutheran School 0742-31-022",
            "St. Francis Xavier 0748-31-001",
            "Community Christian 0912-31-001",
            "Fond Du Lac Ojibwe School 1094-34-030",
            "Bug-O-Nay-Ge-Shig 1115-34-010",
            "Circle Of Life 1435-34-010",
            "Nay-Ah-Shing 1480-34-010",
            "Sacred Heart Area School 2170-31-001",
            "St. Anne's 2397-31-001",
            "St. Mary Of Mt. Carmel 2753-31-002",
            "Rippleside Elementary 0001-01-002",
            "Armatage Elementary 0001-03-103",
            "Lake Harriet Lower Elementary 0001-03-104"
          )
        ),
        row.names = c(NA,
                      -30L),
        spec = structure(list(
          cols = list(
            temp_record_id = structure(list(), class = c("collector_character",
                                                         "collector")),
            district_number = structure(list(), class = c("collector_character",
                                                          "collector")),
            district_type = structure(list(), class = c("collector_character",
                                                        "collector")),
            school_number = structure(list(), class = c("collector_character",
                                                        "collector")),
            grade = structure(list(), class = c("collector_character",
                                                "collector")),
            subject = structure(list(), class = c("collector_character",
                                                  "collector")),
            group_category = structure(list(), class = c("collector_character",
                                                         "collector")),
            student_group = structure(list(), class = c("collector_character",
                                                        "collector")),
            school_year = structure(list(), class = c("collector_double",
                                                      "collector")),
            denominator = structure(list(), class = c("collector_double",
                                                      "collector")),
            numerator = structure(list(), class = c("collector_double",
                                                    "collector"))
          ),
          default = structure(list(), class = c("collector_guess",
                                                "collector")),
          delim = ","
        ), class = "col_spec"),
        class = c("spec_tbl_df",
                  "tbl_df", "tbl", "data.frame")
      )
    
    all_districts <- unique(sort(early$district_name))
    all_schools <- unique(sort(early$school_name_unique))
    
    # Define UI for application that draws a histogram
    ui <- fluidPage(
      # Application title
      titlePanel("EPC Civic Infrastructure Assessment File Prep"),
      
      # Sidebar with a slider input for number of bins
      sidebarLayout(
        sidebarPanel(
          h2("Select Schools to Include"),
          shinyWidgets::pickerInput(
            inputId = "districts",
            label = "Districts:",
            choices = all_districts,
            options = list(`actions-box` = TRUE),
            multiple = TRUE
          ),
          shinyWidgets::pickerInput(
            inputId = "schools",
            label = "Schools:",
            choices = "",
            options = list(`actions-box` = TRUE),
            selected = "",
            multiple = TRUE
          ),
          actionButton(
            inputId = "runButton",
            label = "Preview",
            disabled = TRUE
          ),
          actionButton(
            inputId = "downButton",
            label = "Download",
            disabled = TRUE
          )
        ),
        
        # Show a plot of the generated distribution
        mainPanel(dataTableOutput("early_reading"))
      )
    )
    
    # Define server logic required to draw a histogram
    server <- function(input, output, session) {
      observeEvent(input$districts, {
        if (!is.null(input$districts) && length(input$districts) > 0) {
          shinyWidgets::updatePickerInput(
            session = session,
            inputId = "schools",
            choices = early %>% dplyr::arrange(district_name, school_name_unique) %>% dplyr::filter(district_name %in% input$districts) %>% dplyr::select(school_name_unique) %>% unique() %>% pull()
          )
        } else {
          shinyWidgets::updatePickerInput(
            session = session,
            inputId = "schools",
            choices = "",
            options = list(`actions-box` = TRUE),
            selected = ""
          )
          updateActionButton(session, "runButton", disabled = TRUE)
          updateActionButton(session, "downButton", disabled = TRUE)
        }
      }, ignoreNULL = FALSE)
      
      observeEvent(input$schools, {
        if (!is.null(input$schools) &&
            length(input$schools) > 0 && any(input$schools != "")) {
          updateActionButton(inputId = "runButton",
                             disabled = FALSE)
        } else {
          updateActionButton(inputId = "runButton",
                             disabled = TRUE)
          updateActionButton(inputId = "downButton",
                             disabled = TRUE)
        }
      }, ignoreNULL = FALSE)
      
      observeEvent(input$runButton, {
        if (input$runButton > 0) {
          updateActionButton(inputId = "downButton",
                             disabled = FALSE)
        }
      })
      
      output$early_reading <- renderDataTable({
        if (is.null(input$schools) ||
            any(input$schools == "") || input$runButton == 0) {
          return()
        }
        else{
          early <- early %>%
            dplyr::filter(district_name %in% input$districts,
                          school_name_unique %in% input$schools)
          
          datatable(early)
          
        }
      })
    }
    
    # Run the application
    shinyApp(ui = ui, server = server)
    
    • 1

relate perguntas

  • Adicionar número de série para atividade de cópia ao blob

  • A fonte dinâmica do empacotador duplica artefatos

  • Selecione linhas por grupo com 1s consecutivos

  • Lista de chamada de API de gráfico subscritoSkus estados Privilégios insuficientes enquanto os privilégios são concedidos

  • Função para criar DFs separados com base no valor da coluna

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Vue 3: Erro na criação "Identificador esperado, mas encontrado 'import'" [duplicado]

    • 1 respostas
  • Marko Smith

    Por que esse código Java simples e pequeno roda 30x mais rápido em todas as JVMs Graal, mas não em nenhuma JVM Oracle?

    • 1 respostas
  • Marko Smith

    Qual é o propósito de `enum class` com um tipo subjacente especificado, mas sem enumeradores?

    • 1 respostas
  • Marko Smith

    Como faço para corrigir um erro MODULE_NOT_FOUND para um módulo que não importei manualmente?

    • 6 respostas
  • Marko Smith

    `(expression, lvalue) = rvalue` é uma atribuição válida em C ou C++? Por que alguns compiladores aceitam/rejeitam isso?

    • 3 respostas
  • Marko Smith

    Quando devo usar um std::inplace_vector em vez de um std::vector?

    • 3 respostas
  • Marko Smith

    Um programa vazio que não faz nada em C++ precisa de um heap de 204 KB, mas não em C

    • 1 respostas
  • Marko Smith

    PowerBI atualmente quebrado com BigQuery: problema de driver Simba com atualização do Windows

    • 2 respostas
  • Marko Smith

    AdMob: MobileAds.initialize() - "java.lang.Integer não pode ser convertido em java.lang.String" para alguns dispositivos

    • 1 respostas
  • Marko Smith

    Estou tentando fazer o jogo pacman usando apenas o módulo Turtle Random e Math

    • 1 respostas
  • Martin Hope
    Aleksandr Dubinsky Por que a correspondência de padrões com o switch no InetAddress falha com 'não cobre todos os valores de entrada possíveis'? 2024-12-23 06:56:21 +0800 CST
  • Martin Hope
    Phillip Borge Por que esse código Java simples e pequeno roda 30x mais rápido em todas as JVMs Graal, mas não em nenhuma JVM Oracle? 2024-12-12 20:46:46 +0800 CST
  • Martin Hope
    Oodini Qual é o propósito de `enum class` com um tipo subjacente especificado, mas sem enumeradores? 2024-12-12 06:27:11 +0800 CST
  • Martin Hope
    sleeptightAnsiC `(expression, lvalue) = rvalue` é uma atribuição válida em C ou C++? Por que alguns compiladores aceitam/rejeitam isso? 2024-11-09 07:18:53 +0800 CST
  • Martin Hope
    The Mad Gamer Quando devo usar um std::inplace_vector em vez de um std::vector? 2024-10-29 23:01:00 +0800 CST
  • Martin Hope
    Chad Feller O ponto e vírgula agora é opcional em condicionais bash com [[ .. ]] na versão 5.2? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench Por que um traço duplo (--) faz com que esta cláusula MariaDB seja avaliada como verdadeira? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng Por que `dict(id=1, **{'id': 2})` às vezes gera `KeyError: 'id'` em vez de um TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob: MobileAds.initialize() - "java.lang.Integer não pode ser convertido em java.lang.String" para alguns dispositivos 2024-03-20 03:12:31 +0800 CST
  • Martin Hope
    MarkB Por que o GCC gera código que executa condicionalmente uma implementação SIMD? 2024-02-17 06:17:14 +0800 CST

Hot tag

python javascript c++ c# java typescript sql reactjs html

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve