【问题标题】:R Shiny modularized code - Button not reactingR Shiny模块化代码 - 按钮没有反应
【发布时间】:2021-05-21 11:04:34
【问题描述】:

我正在尝试集成一个按钮以通过我闪亮的应用程序编辑数据框,但该按钮保持无响应,我不知道为什么。我试过用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)

服务器.R

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

【问题讨论】:

  • 嗨 sedsiv,您能否指定需要哪些包来重现您的代码?
  • @cbo 当然更新了

标签: r shinydashboard shiny-reactivity


【解决方案1】:

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

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)

【讨论】:

  • 不,没有任何反应。
  • 对我来说,它会弹出一个带有 countrySelection 列表的页面。
  • 请在记事本中查看弹出窗口。
  • 我让它工作了,弹出窗口似乎被隐藏了,因此它似乎没有响应。
猜你喜欢
  • 2017-05-21
  • 2019-04-28
  • 2021-12-27
  • 1970-01-01
  • 1970-01-01
  • 2018-08-01
  • 2023-01-22
  • 2018-03-22
  • 2016-10-26
相关资源
最近更新 更多