【发布时间】:2021-03-10 00:40:39
【问题描述】:
基于Add a new row with the existing data frame in shiny R by using action button 和adding data input into a empty data frame in R using shiny 这些问题和答案,我正在尝试构建一个可用于数据输入表单的闪亮应用程序。所以在输入4个问题后,用户点击提交,所有字段都被重置并清空,用户可以添加新患者。每次提交后,患者都会被附加到数据框中。我让数据输入工作,但不是单元格的附加和清除。 (理想情况下,还可以选择将整个数据框下载到 excel 中,但我认为这将是下一步)。
library(shiny)
library(shinythemes)
# Define UI -----------
# ---------------------
ui <- fluidPage(theme = shinytheme("sandstone"),
# header
headerPanel("My Shiny Data entry app"),
sidebarLayout(
# sidebar for form
sidebarPanel(
h3("Information",""),
textInput("name", "Patient Name",""),
textInput("age", "Patient Age",""),
textInput("id", "Patient ID",""),
radioButtons("gender", "Patient gender",
c("None selected" = "",
"male",
"female" ,
"other" ,
"do no want to say")),
actionButton("update", "Next patient")
),
# output for viewing
mainPanel(
DT::dataTableOutput("tableDT"),
)
)
)
# Define server logic ------
# --------------------------
server <- function(input, output) {
# process the textinput
table_1 <- reactive({
# creating table
aniRoi2 <- data.frame(Animal_ID = input$name,
Scan_ID = input$age,
Tech_ID = input$id,
Age_weeks = input$gender,
stringsAsFactors = FALSE)
return(aniRoi2)
})
# process the text file and download
# merge two function as data.frame
mytable2 <-eventReactive(input$update,{
table_1()
#cbind.data.frame(table_1(), mytable2())
})
# output as data table
output$tableDT <- DT::renderDataTable(
mytable2()
)
}
# Run the app ----------
# ----------------------
shinyApp(ui, server)
【问题讨论】: