我正在写一个Shinyapp,使用户能够将新条目输入到MongoDB中,并从中删除特定的行。为什么我使用不同的actionLink后,我的Shiny(R)actionButton没有响应?
我想添加一个功能,可以通过保存行的临时副本来撤消上次删除。它似乎工作正常,但在使用撤消之后,出于某种原因,删除按钮不起作用了,我不知道为什么。
我想也许它有一些事实,有一些其他地方,我使用观察员的两个按钮,但我不明白为什么会导致任何问题(我需要他们的应用程序以正常工作) - 无论如何,他们不会阻止我逐一删除多行,只要我不使用undo功能。你可以从下面的代码中看到,我已经在其中加入了一堆print()函数来试图找出它的前进方向。奇怪的是 - 他们都没有出现!就好像删除按钮根本不会在撤消使用后激活脚本。任何想法为什么?
UPDATE:下面是重现问题(不使用的MongoDB)server.R和ui.R短版:
server.R
tempEntry<-NULL
shinyServer(function(input, output, session) {
dat<-data.frame(nums=1:3,ltrs=c("a","b","c"))
## Action: Delete entry
output$delError<-renderText({
input$delButton
isolate({if (!is.na(input$delNum)) {
tempEntry<<-dat[input$delNum,]
output$undo<<-renderUI({
actionLink("undo","Undo last delete")
})
dat<<-dat[-input$delNum,]
print("deleted")
print(dat)
} else print("nope2")
})
})
## Action: Undo delete
output$undoError<-renderText({
input$undo
if (!is.null(input$undo)) {
if (input$undo>0) {
isolate({if (!is.null(tempEntry)) {
dat<<-rbind(dat,tempEntry)
tempEntry<<-NULL
output$delError<<-renderText({""})
print(dat)
} else print("nope3")
}) } else print("undo==0") } else print("undo null")
})
})
ui.R:
library(shiny)
shinyUI(navbarPage("example",
tabPanel("moo",
titlePanel(""),
fluidPage(numericInput("delNum","Row to delete",value=NULL),
actionButton("delButton","Delete row"),
uiOutput("undo"),
div(p(textOutput("delError")),style="color:red"),
div(p(textOutput("undoError")),style="color:blue")
))))
(这也给出了一个错误“参数1(类型'列表')不能由'猫'处理删除一行后,我不知道为什么......但问题不是似乎与此有关)。
谢谢!
你可以给为重现此问题尽可能小的'server.R'和'ui.R'文件? –
嗨Marat,感谢评论。我编辑了我的问题,以包含一个短版本的server.R和ui.R,它重现了这个问题。 – doviod