如何解决R Shiny 模块化代码 - 按钮没有反应
我正在尝试通过我闪亮的应用程序集成一个按钮来编辑数据框,但该按钮没有响应,我不知道为什么。我试过用 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,session) {
moduleControlServer("controlD")
}
解决方法
我不确定预期的行为是否是在记事本中显示一个弹出窗口,如下所示。试试这个
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,session) {
moduleControlServer("Control")
}
shinyApp(ui,server)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。