R Shiny 模块化代码 - 按钮没有反应

R Shiny modularized code - Button not reacting

我正在尝试通过我闪亮的应用程序集成一个按钮来编辑数据框,但该按钮一直没有响应,我不知道为什么。我试过使用 input$'buttonModifyCountryList'input$'Control-buttonModifyCountryList' 访问它,天知道还有什么,但它不会做我想要的。我错过了什么?

require(shiny)
require(shinyjs)
require(shinydashboard)
require(shinydashboardPlus)

countrySelection <- c("AUSTRIA" = "AT", "HUNGARY" = "HU", "GERMANY" = "DE")

moduleControlUI <- function(id, ...) {
  
  ns <- NS(id)
  
  tabsetPanel(
    
    # Account Receivables
    tabPanel(
      title = "Settings: Account Receivables",
      br(),
      
      fluidRow(
        
        boxPlus(
          selectInput(
            inputId = ns("countries"), 
            label = "Countries:",
            choices = countrySelection,
            selected = countrySelection,
            multiple = T
          ),
          actionButton(ns("buttonModifyCountryList"), "Modify Country List"),
          width = 4
        )
      )
    )
  )
}

moduleControlServer <- function(id) {
  
  moduleServer(
    id,
    function(input, output, session) {
      
      observeEvent(input$'Control-buttonModifyCountryList', {
        browser()
        countrySelection <<- edit(countrySelection)
      })
      
    }
  )
  
}

ui.r

header <- dashboardHeader(title = "test")

### Sidebar
sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem("Control",  tabName = "control",   icon = icon("dashboard"))
  )
)

### Body
body <- dashboardBody(
  
  tabItems(
    
    # Control tab content
    tabItem(tabName = "control",
            
      moduleControlUI("Control")
            
    )
  )
)
 
## put UI together --------------------
ui <- dashboardPage(header, sidebar, body)

server.R

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

我不确定预期的行为是否是在记事本中显示弹出窗口 window,如下所示。试试这个

require(shiny)
require(shinyjs)
require(shinydashboard)
require(shinydashboardPlus)

countrySelection <- c("AUSTRIA" = "AT", "HUNGARY" = "HU", "GERMANY" = "DE")

moduleControlUI <- function(id, ...) {
  
  ns <- NS(id)
  
  tabsetPanel(
    
    # Account Receivables
    tabPanel(
      title = "Settings: Account Receivables",
      br(),
      
      fluidRow(
        
        boxPlus(
          selectInput(
            inputId = ns("countries"), 
            label = "Countries:",
            choices = countrySelection,
            selected = countrySelection,
            multiple = T
          ),
          actionButton(ns("buttonModifyCountryList"), "Modify Country List"),
          width = 4
        )
      )
    )
  )
}

moduleControlServer <- function(id) {
  
  moduleServer(
    id,
    function(input, output, session) {
      
      observeEvent(input[["buttonModifyCountryList"]], {
        #browser()
        countrySelection <<- edit(countrySelection)
      })
      
    }
  )
  
}
## ui.r

header <- dashboardHeader(title = "test")

### Sidebar
sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem("Control",  tabName = "control",   icon = icon("dashboard"))
  )
)

### Body
body <- dashboardBody(
  
  tabItems(
    
    # Control tab content
    tabItem(tabName = "control",
            
            moduleControlUI("Control")
            
    )
  )
)

## put UI together --------------------
ui <- dashboardPage(header, sidebar, body)

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

shinyApp(ui, server)