我正在尝试在Shiny中实现CRUD工作流程(创建/读取/更新/删除)以管理数据库记录。看起来Shiny默认不支持这种工作流程,所以我想知道是否有一种简洁的方法可以实现。
为了缩小问题的范围,我很难向记录表中添加静态链接,指向特定的tabPanel以编辑相应的记录。
以下是一个模拟示例,以便更容易地解决此问题。
ui.R
library(shiny)
shinyUI(navbarPage("Example",
tabPanel("Event List",
sidebarLayout(
sidebarPanel(list(
p("If you click the link, it should go to the edit event panel."),
p("But it's not...")
), align="left"),
mainPanel(
h3("Event List"),
tableOutput('testTable'),
dataTableOutput('events_table'),
align="center"))),
tabPanel("Edit Event", id='edit',
sidebarLayout(
sidebarPanel(
uiOutput("choose_event_id"),
align="center"),
mainPanel()
)),
id='top'
))
服务器.R
library(shiny)
shinyServer(function(input, output, session) {
output$choose_event_id <- renderUI({
selectizeInput("event_id", "Event", width='100%',
choices=c(1,2,3), selected=1)
})
output$testTable <- renderTable({
require(xtable)
table <- xtable(data.frame(A=1,B='<a href="LINK-HERE">test</a>'))
table
}, sanitize.text.function = function(x) x)
})
我需要弄清楚的是LINK-HERE部分。tabPanels链接在每次重新启动应用程序时都会更改,因此静态链接在这种情况下不起作用。
第二个问题是将要编辑记录的id传递到URL中,但如果需要可以留待跟进问题。 我将尝试使用来自此SO问题答案的方法:
Shiny saving URL state subpages and tabs
提前致谢。