2013-12-09 118 views
1

我正在使用2个表格,1个图形和一个条件答案的Shiny应用程序。直接在r里添加行闪亮的应用程序

我想直接在Shiny中添加一行到表中并更新结果。

例如,在一个带有id,2个日期和2个倍数选项问题的表格中。我有3个观测值,我希望用户能够添加n others观测值,这会导致其他表和图更新为新的观测值。

可能吗?如果是,你如何做到这一点?

谢谢你,原谅我可怜的英语。

这里我闪亮的应用 http://www.hostingpics.net/viewer.php?id=459723Shiny.png

这里的链接谁的工作代码:

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

我已经尝试一下本作我的问题:

**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) 

但那不起作用

+0

添加你到现在为止所尝试的。如果他们可以看看你的尝试,Stackoverflow社区将能够帮助你。 – Yogesh

+0

感谢您的帮助,我只是更新我的文章 – user3083101

回答

0

终于让我找到一个办法做到这一点,

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"), 

输入数据文件中的文本,并用在函数read.table写你的代码的开始你可以更新你的表格。但是你需要重新启动你的应用程序。有可能是一个更好的办法,在无需重新启动应用程序更新,但我还没有找到它

您可以使用下面的功能,避免数据缺省的一读(在计算器一个其他问题找到(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(.... 

    }) 
1

一种方法是依靠shinyIncubator包的matrixInput功能的shinyIncubator包有发展的功能,有时最终与shiny合并。鉴于其amazingness,我希望matrixInput或类似的东西会成为我们有生之年基数shiny的一部分

我做了一个演示:

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

对我来说最难的部分就是matrixInput以显示其colnames,其默认是隐藏的。你需要做的是自定义显示风格。你可以用css来做到这一点,或者像我一样,用你的ui.R使用标签。关键是要将display: table-header-group分配到.tableinput .hide。其他显示功能可以通过使用浏览器的inspect element选项找到:Firefox和Chrome都具有该功能;其他浏览器可能也会这样。

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