还记得并在R Shiny应用程序中显示所有用户输入吗?

时间:2019-06-21 17:06:41

标签: r shiny

在R Shiny应用程序中,是否可以记住所有用户输入并打印出结果?

当前应用将允许用户上载.csv数据文件,之后他们可以转到概率选项卡之一并输入新的数据信息。这将为每个新条目提供新的预测概率。

例如,如果用户输入“ FIB-4”的新值,则他们将获得输出“新FIB-4值为:[值],并且每次用户除了之前输入的所有内容外,还为FIB-4提交了新值。因此,主面板将显示新的FIB-4值,例如4和10:

“新的FIB-4值为:4,新的预测值为0.48”

“新的FIB-4值为:10,新的预测值为0.58”

我从this postthis post看到reactiveValue可能是行之有效的方法,但是我是否需要一个“ order”计数器来按顺序保存所有值?

ui<-navbarPage("R268 - Fibroscan analysis (Program adapted from Subhasish code) ",
           tabPanel("Data Import",
                    sidebarLayout(sidebarPanel( fileInput("file","Upload your CSV",multiple = FALSE),
                                                tags$hr(),
                                                h5(helpText("Select the read.table parameters below")),
                                                checkboxInput(inputId = 'header', label = 'Header', value = FALSE),
                                                checkboxInput(inputId = "stringAsFactors", "stringAsFactors", FALSE),
                                                radioButtons(inputId = 'sep', label = 'Separator', 
                                                             choices = c(Comma=',',Semicolon=';',Tab='\t', Space=''), selected = ',')
                    ),
                    mainPanel(uiOutput("tb1"))
                    ) ),
 tabPanel("Probability of discordance between fibroscan and biopsy",
                    sidebarLayout(sidebarPanel( 
                      numericInput("fib4", "Enter new FIB-4 value:", 1.72, min = 0, max = 20),

                      actionButton("update2", "Update")
                    ),
                    mainPanel(helpText("The probability of discordance between Fibroscan and biopsy is: "),
                              verbatimTextOutput("print_prob2"))
                    ) )
)
server<-function(input,output) { 

   data <- reactive({
   file1 <- input$file
   req(file1) 
   read.table(file=file1$datapath, sep=input$sep, header = input$header, stringsAsFactors = input$stringAsFactors)
 })
output$table <- renderTable({
     if(is.null(data())){return ()}
     data()
})
output$tb1 <- renderUI({
     tableOutput("table")
})
prob_discFibBiop<-eventReactive(input$update2,{
    if(is.null(data())){return ()}
    rm(list = ls())
    f<-data()

    subdat <- f[,c("Dis.Fibrosis.FS.vs.Bx..0.no.discordance..1.Results.discordant..Adv_vs_NonAdv","Fib4")]
    subdat <- subdat[complete.cases(subdat),]

    library(caret)
    form <- sprintf("%s~%s","Dis.Fibrosis.FS.vs.Bx..0.no.discordance..1.Results.discordant..Adv_vs_NonAdv",c("Fib4"))

    logreg <-glm(as.formula(form),family=binomial(),data=subdat)
    pred <- predict(logreg, newdata=data.frame(Fib4 = input$fib4),type="response")
    pred <- round(pred, 2); pred.output <- cbind(pred,1-pred); colnames(pred.output) <- c("Discordant","No discordance")
    return(pred.output)
 })

output$print_prob2 <- renderPrint({

  print.output <- paste0("New FIB-4 input: ", input$fib4, " will result in ", prob_discFibBiop())
  print(print.output)
})
}
shinyApp(ui=ui,server=server)

0 个答案:

没有答案