我已将 R6 类定义为全局函数并尝试在模块中使用它。R6 函数是事件响应函数,预计在单击按钮时初始化类中的新元素。尽管代码运行正常,但它并没有创建新元素。
ns <- NS(id)
div(class = "ui form", id= "stox", style = "text-align: center; color: black",
h4(class= "ui top attached header", "You don't have a portfolio. Please create your Portfolio first"),
div(class = "ui bottom attached segment",
h4(class= "ui dividing header"),
div(class= "ui inverted form",
div(class= "two fields",
div(class= "field",
"Portfolio Name", text_input(ns("ex"), label = "Portfolio Name", type = "text", placeholder = "Stoxx11")),
div(class= "field",
actionButton(ns("submitpf"), "Submit!", class = "btn-success"))
))))
}
pfcreate_server <- function(id) {
moduleServer(id, function(input, output, session) {
eventReactive(input$submitpf, {
New<- Portfolio$new(as.character(input$ex), as.character(user()), as.character(Game_list[[id]]$name), as.numeric(Game_list[[id]]$Size), as.numeric(Game_list[[id]]$Size))
Game_list[[id]]$NewPortfolio(New)
Game_list[[id]]$NewChallenger(user())
})
})
}```