R,监视变量并更新ui
我正在尝试在一个闪亮的应用程序中创建一个消息系统,当某些任务完成时,它会收到通知,但目前它不起作用: 用户界面: 服务器:R,监视变量并更新ui,r,shiny,reactive-programming,shinydashboard,R,Shiny,Reactive Programming,Shinydashboard,我正在尝试在一个闪亮的应用程序中创建一个消息系统,当某些任务完成时,它会收到通知,但目前它不起作用: 用户界面: 服务器: library(shinydashboard) shinyServer(function(input, output) { M_Store <- reactiveValues(DF = data.frame( from = c("Admininstrator", "New User", "Support"), message = c(
library(shinydashboard)
shinyServer(function(input, output) {
M_Store <- reactiveValues(DF = data.frame(
from = c("Admininstrator", "New User", "Support"),
message = c(
"Sales are steady this month.",
"How do I register?",
"The new server is ready."
),
stringsAsFactors = FALSE
))
output$messageMenu <- renderMenu({
msgs <- apply(M_Store$DF, 1, function(row) {
messageItem(from = row[["from"]], message = row[["message"]])
})
dropdownMenu(type = "messages", .list = msgs)
})
reactive({
input$go
message("Button pressed. Execute analysis!")
message("Pretend analysis got done!")
message("Now want to send a message that the analysis is done!")
M_Store$DF <- rbind(isolate(M_Store$DF), data.frame(from="Meee", message="Done message!"))
})
reactive({
input$go2
message("Second button pressed. Execute second analysis!")
message("Some computation!")
message("Want to update the user on progress with a message!")
M_Store$DF <- rbind(isolate(M_Store$DF), data.frame(from="Someone else!", message="Progress message2!"))
message("More computations....")
message("Done, want to tell user I'm done!")
M_Store$DF <- rbind(isolate(M_Store$DF), data.frame(from="Someone else!", message="Done message2!"))
})
})
库(ShinydaShashboard)
shinyServer(功能(输入、输出){
M_Store您可以将reactiveValues
功能与隔离功能结合使用。您的案例看起来像:
messageData <- data.frame(from = character(0), message = character(0), stringsAsFactors = F) #simplified this a bit
shinyServer(function(input, output) {
M_Store <- reactiveValues(DF = messageData)
newMessage <- reactive(data.frame(from = as.character(input$from),message = as.character(input$message)))
observe({
M_Store$DF <- rbind(isolate(M_Store$DF), newMessage())
})
output$myUI <- renderUI({
#some code
... M_Store$DF ...
#some code
})
})
每当input$go
的值发生变化时(每次按下按钮时),就会触发该命令。如果您将其他输入值或响应值放在此处,您可以将其与其他流程或ui元素绑定我尝试的是将其绑定,以便当有人执行某些操作时,例如加载数据或执行某些分析,在操作完成后,会将消息推送到messageData,并显示在ui中。将生成特定消息d当某个反应式表达式(例如依赖于输入的t检验)结束时。我刚刚编辑了问题,用一个玩具示例显示了我想要做的事情。(但不起作用)
messageData <- data.frame(from = character(0), message = character(0), stringsAsFactors = F) #simplified this a bit
shinyServer(function(input, output) {
M_Store <- reactiveValues(DF = messageData)
newMessage <- reactive(data.frame(from = as.character(input$from),message = as.character(input$message)))
observe({
M_Store$DF <- rbind(isolate(M_Store$DF), newMessage())
})
output$myUI <- renderUI({
#some code
... M_Store$DF ...
#some code
})
})
observeEvent(input$go,{
message("Button pressed. Execute analysis!")
message("Pretend analysis got done!")
message("Now want to send a message that the analysis is done!")
M_Store$DF <- rbind(isolate(M_Store$DF), data.frame(from="Meee", message="Done message!"))
})