I'm trying to implement a CRUD workflow (Create/Read/Update/Delete) in Shiny to manage database records. It seems Shiny does not support this kind of workflow by default, so I'm wondering if there is a clean way to achieve this.
To narrow the scope of the question, I'm having a hard time adding static links to a table of records pointing to a specific tabPanel to edit the corresponding record.
Here is a mockup example to make it easier to troubleshoot this problem.
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'
))
server.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)
})
The LINK-HERE part is what I'm trying to figure out. tabPanels links change every time the app is restarted, so static links do not work in this case.
A second issue would be to pass the id of the record to be edited in the URL, but this could be left for a follow up question if necessary. I'll try to achieve this by using the approach from the answer of this SO question:
Shiny saving URL state subpages and tabs
Thanks in advance.