I'm trying to avoid hard-coding to print the inputs of 10 text-inputs.
Basically the user feeds in keywords that generates the appropriate SQL code as text.
SERVER.R
Code Block 1:
So the first block of code is creating the ten text inputs – these are created using renderUI and outputted using uiOutput
output$key1A_depend1 <- renderUI({
lapply(1:5, function(i){
textInput(paste0("key1_temp_",i),label=paste0(i),paste0(""))
})#END lapply
})#END renderUI
output$key1A_depend2 <- renderUI({
lapply(6:10, function(i){
textInput(paste0("key1_temp_",i),label=paste0(i),paste0(""))
})#END lapply
})#END renderUI
# THE ABOVE WORKS FINE
Code Block 2:
The second block of code is then assigning text-based outputs based on what is entered in the text inputs. These conform to “” or no text if nothing is inputted in the text inputs.
output$key1A_main <- output$key1A_maincopy <- output$key1A_maincopy2 <- renderUI({
for (i in 1:10){
xy <- eval(parse(text=paste0("input$key_temp_",i)))
assign(paste0("key1A_out_",i),
if(!is.null(xy)) {
paste0("Details like '%",xy,"%' or ",br())
}
else paste0(" ")
)
}#END for
# HARD CODING THE ABOVE INTO 10 SEPARATE STATEMENTS ALSO WORKS, JUST NOT IN THE FOR LOOP
Code Block 3:
The third block of code is generating the actual output, collating all outputs generated in the second block of code.
HTML(paste0( key1A_start
key1A_out_1
, key1A_out_2
, key1A_out_3
, key1A_out_4
, key1A_out_5
, key1A_out_6
, key1A_out_7
, key1A_out_8
, key1A_out_9
, key1A_out_10))
})#END renderUI`enter code here`
# THE OUTPUT GENERATED RETURNS BLANKS for Kkey1A_out_1, 2, 3 …. , 10.
However when I hard-code values Code Block 2, it works perfectly
Alternate Code Block 2:
key1A_out_1 <-
if(nchar(input$key1_temp_1)>0)
{paste0("Details like '%",input$key1_temp_1,"%' OR ",br()) }
else
{paste0(" ") }
# REPEATED 10 times
Any help would be appreciated, it could either be a scoping issue or just something that assign() doesn't do properly.