What is the cleanest way to implement CRUD workflow in R Shiny?

I am trying to implement a CRUD workflow (Create / Read / Update / Delete) in Shiny to manage database records. Shiny doesn't seem to support this like a default workflow, so I'm wondering if there is a clean way to achieve this.

To narrow down the range of questions, it is difficult for me to add static links to the records table pointing to a specific tabPanel for edit the corresponding record.

Here is a sample layout to make troubleshooting this problem easier.

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 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 understand. tabPanels change every time the application restarts, so static links in this case do not work.


The second question should be to pass the record identifier edited in the URL, but this can be left to the next question, if necessary. I will try to achieve this using the approach from the answer to this question:

Shiny tabs and URL status status tabs

Thanks in advance.

+6
source share

Source: https://habr.com/ru/post/982997/


All Articles