Add rows directly in a r shiny apps

I'm working on a Shiny app with 2 tables, 1 graph and a conditional answer .

I want to add a row to a table directly in Shiny and update results.

For example, in a table with an id, 2 dates and 2 multiples choices questions. I have 3 observations and I want a user to be able to add n others observations, which should cause the other table and graph to update with this new observations.

Is it possible? If yes how do you do this?

Thank you, forgive my poor english.

Here a link of my Shiny apps http://www.hostingpics.net/viewer.php?id=459723Shiny.png

and here the code who work :

https://gist.github.com/wolf6541/7874968

i have already try this for my question :

**Ui.r**
 #Titre
    h3("Ajout d'un nouveau patient"), 

#Date inclusion
dateInput("date_inclu", "Date de l'inclusion", value = ,language = "fr"),

#Date reponse
dateInput("date_rep", "Date de reponse", value = ,language = "fr"),

#Dose
textInput("dose", "Dose administree", ),

#Reponse
textInput("tox", "Reponse toxicite", ),

updateData()


**Server.R**
    identifiant =length(data_time$identifiant)
    dose =reactive(input$dose)
    date_inclusion =reactive(input$date_inclu)
    date_reponse =reactive(input$date_rep)
    reponse =reactive(input$tox)

    nouveau_pat = cbind(identifiant,  dose,  date_inclusion,    date_reponse,   reponse)
    nouveau_pat = as.data.frame(nouveau_pat)

    data_time = rbind(data_time,nouveau_pat)

but that doesn't work

Answers


One way to do this is to rely on the matrixInput function of the shinyIncubator package. The shinyIncubator package has development features that are sometimes eventually merged with shiny. Given its amazingness, I expect that matrixInput or something like it will be part of base shiny within our lifetimes.

I made a demo:

library("shiny")
library("shinyIncubator")
runGist("https://gist.github.com/anonymous/8449201")

For me the hardest part was getting matrixInput to show its colnames, which are hidden by default. What you need to do here is customize the display style. You can do this in a css or, as I did, in the body of your ui.R using tags. The key is to assign display: table-header-group to .tableinput .hide. Other display features can be found by using the inspect element option of your browser : Firefox and Chrome both have that feature; other browsers probably do too.

tags$head(
  tags$style(type = "text/css"
    , ".tableinput .hide {display: table-header-group;}"
  )
)

Finally i found a way to do this,

server.R

#Stockage des donnes
  makeData <- observe({
    Data
    write.table(t(c(input$Identifiant,
                    as.character(input$datei),
                    input$dose,
                    as.character(input$dater),
                    input$reponse)),file="donnees",sep="\t",col.names=F,row.names=F,append=T)
  })

  #affichage table pat
  output$table_pat <- renderTable({
    table_pat = data.frame(Identifiant = input$Identifiant,
                           Date_inclusion =as.character(input$datei),
                           Dose = input$dose,
                           Date_reponse =as.character(input$dater),
                           Reponse = input$reponse)
  },include.rownames=FALSE)

ui.r

shinyUI(pageWithSidebar(
  headerPanel("OPTIMUM TRIAL"),

  sidebarPanel(

    h3("Ajout d'un nouveau patient"),
    #Identifiant
    textInput("Identifiant","Identifiant du patient:",value =""),

    #Dose
    selectInput("dose", "Dose:",
                c(1,2,3,4,5,6), selected = 1),
    #Toxicite
    selectInput("reponse", "Reponse:",
                c("Succes","Echec"), selected = "Succes"),

    #Date inclusion
    dateInput("datei", "Date de l'inclusion:", format = "yyyy-mm-dd",value =Sys.Date(),language = "fr"),

    #Date reponse
    dateInput("dater", "Date de reponse:", format = "yyyy-mm-dd",value =Sys.Date(),language = "fr"),

    submitButton("Ajouter le patient"),

    h3("Supprimer un patient"),

    textInput("Supprimer","Identifiant du patient a supprimer:", value = ""),

    submitButton("Supprimez le patient")

  ),

  mainPanel(

    h3("Nouveau patient"),
    tableOutput("table_pat"),

    h3("Historique des patients"),
    tableOutput("Data"),

Input data are write in a file text and with a read.table in the beginning of your code you can update your table. However you need to restart your app. There is probably a better way that allows to update without restarting the app but I have not found it

You can use the following function to avoid the first reading of data defaults (find in a other question in stackoverflow (Delayed execution in R Shiny app)

#Fonction pour ne pas imprimer lors du lancement de la page
  values <- reactiveValues(starting = TRUE)
  session$onFlushed(function() {
    values$starting <- FALSE
  })

  #Stockage des donnees
  makeData <- observe({
    if (values$starting){
      return(NULL)}

    else {
      write.table(....

  })

Need Your Help

Get domain of server where swf is being called

javascript jquery actionscript-3 flash

I have SWF hosted on a domain lets say www.aaa.com. I am embedding that swf in an html page which is on www.bbb.com. Now, within the SWF, how can I get the domain where SWF is being embedded i.e. i...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.