I'm creating a shiny app with the shinydashboard library.
Right now I am testing what are notifications (alerts messages etc ...)
My question is how do you manage these notifications (create, modify or delete) In the documentation of shinydashboard indicate how they are created therefore in that there is no problem, my question is how I do so that it is deleted, for example, a message when you have seen or clicked.
For now I've tried this:
server.R
output$mensajes <- renderMenu({
from <- c("A","B")
content <- c("Mensaje 1","Mensaje2")
messages <- data.frame(from,content)
msgs <- apply(messages, 1, function(row) {
messageItem(from = row[["from"]], message = row[["content"]],href = paste0("javascript:mensaje('",row[["content"]],"')"))
})
dropdownMenu(type = "messages", .list = msgs
)
})
app.js
function mensaje(msg){
alert(msg);
}
Obviously this what it does is that when you click on the message you get an alert with the content of the message, the problem is that I'm interested in this message being deleted after seeing it.
On the other hand I think that doing it with js is not the right thing to do since the changes are not saved in the data frame when you do it.
EDITED
Starting with another question formulate, I have been able to manage (more or less) the messages, so that when you click on the table you mark them as read messages.
Now, what interests me is to communicate the js with the application (for now I have sent data from the application to the js but not the reverse).
As it could be very broad the answer I commented what I had thought more or less.
- When you press the message notification, mark it as read and update the notification menu and message table.
- When you press the message notification, it redirects you to the message table.
I leave the most updated code
Server.R
output$mensajes <- renderMenu({
if(nrow(messages[which(messages$leido == FALSE),]) >0) {
msgs <- apply(messages[which(messages$leido == FALSE),], 1, function(row) {
messageItem(from = row[["from"]], message = row[["content"]],href = paste0("javascript:mensaje('",row[["content"]],"')"))
})
}else{
msgs = NULL
}
dropdownMenu(type = "messages", .list = msgs)
})
output$tablaMensajes <- DT::renderDataTable({
messages
})
observe({
if(! is.null(input$tablaMensajes_rows_selected)){
#browser()
messages
s<-input$tablaMensajes_rows_selected
messages[s,"leido"] <<- TRUE
output$mensajes <- renderMenu({
if(nrow(messages[which(messages$leido == FALSE),]) >0) {
msgs <- apply(messages[which(messages$leido == FALSE),], 1, function(row) {
messageItem(from = row[["from"]], message = row[["content"]],href = paste0("javascript:mensaje('",row[["content"]],"')"))
})
}else{
msgs = NULL
}
dropdownMenu(type = "messages", .list = msgs)
})
output$tablaMensajes <- DT::renderDataTable({
messages
})
}
})
The js is still the same as I can not understand very well how it communicates with server.R
app.js
function mensaje(msg){
alert(msg);
}
I do not attach the ui.R
since it seems to me that the information there is not relevant.
Greetings.