I need help writing a shiny app that will spit out a separate datatable after entering into each respective input and clicking the actionbutton. I got the app to simply output to the datatable, but it will overwrite upon a new entry. I checked the reference section of R Shiny and it seems I need to use insertUI() but I don't really understand Shiny very well to figure it out. Please help. Thanks.
library(shiny)
library(rhandsontable)
#UI
ui <-shinyUI(fluidPage(
titlePanel('Drug Prep'),
sidebarPanel(textInput('expid','Experiment ID'),
textInput('nsc','NSC Number'),
textInput('solvent','Solvent'),
numericInput('stkcon','Stock Conc(mg/ml)',0),
numericInput('Repeat','Repeat',0),
textAreaInput('instruct','Instructions',height='50px'),
numericInput('amt','Amt to weigh(mg)',0),
numericInput('vehicle','Tot_vol of vehicle(ml)',0),
hr(),
numericInput('grp','Group',0),
numericInput('micedose','Mice Dose/vial',0),
numericInput('dose','Dose(mg/kg)',0),
numericInput('doseconc','Dose Concentration(mg/ml)',0),
numericInput('numvial','No. of Vials',0),
numericInput('volA','Vol of Vehicle_A(ml)',0),
numericInput('volB','Vol of Vehicle_B(ml)',0),
numericInput('volC','Vol of Vehicle_C(ml)',0),
br(),
actionButton('save','Save')
),
mainPanel(
textOutput('nsc'),
verbatimTextOutput('instruct'),
uiOutput("hot"),
hr(),
uiOutput('hot2')
)
)
)
#SERVER
server=function(input, output) {
global <- reactiveValues()
observeEvent(input$save, {
global$data[[length(global$data) + 1]] = data.frame(ExpID=input$expid,NSC=input$nsc,Stock.conc=input$stkcon,
Repeats=input$Repeat,Amt=input$amt,vol=input$vehicle,
stringsAsFactors = F)
})
observeEvent(input$save, {
global$ditto[[length(global$ditto) + 1]] = data.frame(group=input$grp,No_of_mice_dosed=input$micedose,dose=input$dose,dose_conc=input$doseconc,
No_vial=input$numvial,vol_Vehicle_A=input$volA,vol_Vehicle_B=input$volB,vol_Vehicle_C=input$volC,
tot_vol=input$volA+input$volB+input$volC,stringsAsFactors = F)
})
observeEvent(input$save, {
for(nr in 1:length(global$data)){
local({
df <- global$data[[nr]]
output[[paste0("hot", nr)]] <- renderRHandsontable(rhandsontable(df))
})
}
})
observeEvent(input$save, {
for(nr in 1:length(global$ditto)){
local({
df<-global$ditto[[nr]]
output[[paste0('hot2',nr)]] <- renderRHandsontable(rhandsontable(df))
})
}
})
output$instruct<-renderText({input$save
paste(isolate(input$nsc),isolate(input$instruct),sep='\n')
})
output$hot <- renderUI({
lapply(1:length(global$data), function(nr) rHandsontableOutput(paste0("hot", nr)))
})
output$hot2<-renderUI({
lapply(1:length(global$ditto), function(nr) rHandsontableOutput(paste0("hot2", nr)))
})
}
shinyApp(ui = ui, server=server)
I want the app to minic this excel spreadsheet, notice how the amount of columns differ for each table (submission).