Created
February 6, 2013 15:43
-
-
Save ramnathv/4723392 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
# Sample database | |
patient <- data.frame(PatientID = LETTERS[1:5], | |
Name = letters[1:5],stringsAsFactors=FALSE) | |
record <- data.frame(PatientID = rep(patient$PatientID,3)) | |
record$RecordID <- paste(PatientID=patient$PatientID, | |
sample(LETTERS[1:26],15),sep="_") | |
record$Title <- sample(letters[1:26],15) | |
shinyServer(function(input, output) { | |
output$choose_PatientID <- reactiveUI(function() { | |
selectInput("PatientID", "PatientID",patient$PatientID) | |
}) | |
output$edit_Name <- reactiveUI(function() { | |
if(is.null(input$PatientID)) | |
return() | |
name <- patient[input$PatientID==patient$PatientID,"Name"] | |
textInput("Name", "Name",name) | |
}) | |
output$choose_Record <- reactiveUI(function() { | |
PatientID <- input$PatientID | |
if(is.null(PatientID)) | |
return() | |
records <- record[PatientID==record$PatientID,"RecordID"] | |
selectInput("RecordID","RecordID",records) | |
}) | |
output$edit_Record <- reactiveUI(function() { | |
RecordID <- input$RecordID | |
if(is.null(RecordID)) | |
return() | |
title <- record[RecordID==record$RecordID,"Title"] | |
textInput("Title", "Title",title) | |
}) | |
updatePatient <- function(){ | |
PatientID <- input$PatientID | |
patient[patient$PatientID==PatientID,"Name"]<<- input$Name | |
} | |
updateRecord <- function(){ | |
RecordID <- input$RecordID | |
record[record$RecordID==RecordID,"Title"]<<- input$Title | |
} | |
output$save <- reactive(function(){ | |
save = input$save; | |
if(is.null(save) || save ==0) | |
return(NULL) | |
isolate({ | |
cat("Saved\n") | |
updatePatient() | |
updateRecord() | |
}) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(shinyIncubator) | |
shinyUI(pageWithSidebar( | |
headerPanel("Editable Master Detail"), | |
sidebarPanel( | |
uiOutput("choose_PatientID"), | |
uiOutput("edit_Name"), | |
br(), | |
uiOutput("choose_Record"), | |
uiOutput("edit_Record"), | |
actionButton("save","Save") | |
), | |
mainPanel() | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment