我遇到了轻微的问题(bug也许?)与Shiny的书签 - 我创建动态UI - 新的文本和数字输入。这些输入是通过单击ActionButton创建的。保存书签网址时 - 数字和文字输入的值都在此URL中。到现在为止还挺好。但是,加载保存的URL后,我只能看到第一个动态创建的用户界面。我必须点击动作按钮来添加下一个数字和文本输入。这些值保存在URL中,一旦添加了这些输入,它们就会被填充正确的保存值。但是,如果你有20个这样的按钮,那么它会有点不方便,你必须点击19次才能将它们全部放到屏幕上。 这是一个简短的可重复使用的例子。R Shiny - 书签动态创建的用户界面
library(shiny)
ui <- function(request){
shinyUI(fluidPage(
bookmarkButton(),
sidebarLayout(
actionButton('addElement', 'Add Element', icon("plus"), class="btn-success text-white"),
mainPanel(
id ="content"
)
)
))
}
shinyServer(function(input, output) {
enableBookmarking("url")
countvar <<- 0
observeEvent(input$addElement, {
countvar <<- countvar + 1
element <- paste0("var", countvar)
insertUI(
selector = "#content",
where = "beforeEnd",
ui = tagList(
wellPanel(
style = "display:-webkit-inline-box;width:100%",
id = element,
column(3,
textInput(element, "Element name")
),
column(3,
numericInput(paste0(element, "Value"), "Element Value", NULL)
)
)
)
)
})
})
我发现SO,遗憾的是没有答案类似的问题 - Shiny app bookmarking: dynamic UI input lost
您需要使用'OnRestore中()'函数。看看这篇文章:https://shiny.rstudio.com/articles/advanced-bookmarking.html –
嗨芭芭拉,感谢您的链接。我想我会看到问题出在哪里 - 即使是在addElement的值超过1的URL中,也只会触发一次。然而,我不知道我应该如何将'onRestore()'函数合并到我的代码中。我究竟应该调用什么 - 触发代码的“observeElement”部分?或者干脆在纯HTML中解析?谢谢,我在这一点上有点失落。 – ledogbert