我正在努力根据模块中的代码更新 ui 中的按钮的逻辑。当我单击按钮时,我希望它改变颜色,但没有任何反应。我理解为了在服务器模块中使用它而使 ui 输入反应,但我没有让它以相反的方式工作。高度赞赏帮助(和一些解释)!
这是我的代码:(我在点击时将保存到 csv 部分,因为我让它工作)。
library(shiny)
library(shinyBS)
module_company_ui<-function(id){
# `NS(id)` returns a namespace function, which was save as `ns` and will
# invoke later.
ns <- NS(id)
tagList(
radioButtons(ns("company_name"), label= "Is the << COMPANY NAME >> correct?",
c("choose from below" = "10",
"correct" = "0.15",
"correct, but some noise" = "0.075",
"not sure" = "0.05",
"wrong" = "0"),selected = character(0)),
textOutput(ns("txt")),
bsButton(ns('save_inputs'), " Save", type="action", block=TRUE, style="info", icon=icon(name="save"))
)
}
module_save_inputs<-function(id, value_company){
moduleServer(
id,
## Below is the module function
function(input, output, session) {
save<-reactive(input$save_inputs)
observeEvent(save(), {
updateButton(session, "save_inputs",label = " Save", block = T, style = "success", icon=icon(name="save"))
})
})
}
ui <- fluidPage(
module_company_ui("company")
)
server <- function(input, output, session) {
module_save_inputs("company")
}
shinyApp(ui, server)