Soluction to plot graph with input values

Hi people.

I need to plot a graph after the user enter with many Inputs, for the R search for these inputs in a Database, and next, plot the graph.

Ordering my idea:

1- I have the following list of inputs in UI code:

  
                               
                               numericInput(inputId= "diametro", label= "Diametro do Aco:", value= 0),
                               
                               numericInput(inputId= "parede", label= "Parede:", value= 0),
                               
                               textInput(inputId= "grau", label= "Grau:", value= 0),
                               
                               textInput(inputId= "aqa", label= "AQA:", value= 0),
                                                                                           
                               numericInput(inputId= "ciclo", label = "Ciclo:", value = 0),
                               

2- ONLY WHEN the user INSERT ALL THESE VALUES, the program will search in database to plot a graph with the following code:

tabela_saida = df

valor_le = df$LE

valor_tr = df$TR

relacao_ts = (valor_le/valor_tr)
#------------------------------------Calculo pra Capabilidade---------------------
capabilidade_LE <- valor_le
capabilidade_LE = matrix(valor_le, nrow = 1, ncol = length(valor_le), byrow = TRUE)
normalidade_LE = matrix(valor_le, nrow = length(valor_le), ncol = 1, byrow = TRUE)


capabilidade2 <- relacao_ts
capabilidade2 = matrix(relacao_ts, nrow = 1, ncol = length(relacao_ts), byrow = TRUE)
normalidade2 = matrix(relacao_ts, nrow = length(relacao_ts), ncol = 1, byrow = TRUE)

How can I create a soluction for the plot to do this last code, only when all the inputs have been insert?

Will actionButton not help? Have you tried it?

1 Like

I tried. Maybe I made a mistake about how to plot the graph passing the values after the actionButton was pressed.

I'll try again.

When you want to delay processing till the last input is received, your best bet is actionButton.
It should work. It's pretty simple.

1 Like

Look my code for observeEvent

UI:

 actionButton("plot", "Plotar!"),

SERVER:

#-----------------------START OBSERVE--------------------------------
  
  observeEvent(input$plot,
  
  #-------------------------Campo gerar histograma--------------------------
  
  output$histograma <-renderPlot({
    capabilidade_LE = qcc(data = capabilidade_LE, type="xbar", plot = TRUE)
    process.capability(object = capabilidade_LE, spec.limits = c(input$lininf,input$linsup))
  }),
  
  #-------------------------------------------------------------------------
  
  output$histograma2 <-renderPlot({
    capabilidade2 = qcc(data = capabilidade2, type="xbar", plot = TRUE, lines(x = "red", y = "yellow"))
    process.capability(object = capabilidade2, spec.limits = c(input$lininf,input$linsup))
  }),
  
  #------------------------Grafico de normalidade---------------------------
  
  output$normalidade <-renderPlot({
    ss.study.ca(normalidade_LE, LSL = input$lininf, USL = input$linsup, Target = ((input$lininf+input$linsup)/2),alpha = 0.05, f.main = "Teste de Normalidade")
    
  }),
  
  #-------------------------------------------------------------------------
  output$normalidade2 <-renderPlot({
    ss.study.ca(normalidade2, LSL = input$lininf, USL = input$linsup, Target = ((input$lininf+input$linsup)/2),alpha = 0.05, f.main = "Teste de Normalidade")
    
  })
  
  
  )    #Close OBSERVE

BUT, i need to Source my SERVER.R with another file called DATA.R, where contains my SQL code to find some data in DATABASE to plot a graph. Look:

DATA.R

query <- 
  "select 
cod_ordem_producao as Ordem,
dim_ext_tubo as Diametro,
esp_par_tubo as Parede,
cod_aqa as AQA,
tmo_ciclo_plan as Ciclo,
dth_criacao_reg as Data,
dsc_aco as Grau,

val_lim_escoamento as LE,
val_tensao_residual as TR
from
QT_QTS.PLA_ORDEM_PRODUCAO

where DIM_EXT_TUBO = 244.48
and esp_par_tubo = 11.99
and VAL_LIM_ESCOAMENTO != 0

order by DTH_CRIACAO_REG desc"

df <- dbGetQuery(
  connection_reportUser,
  query
)
df

tabela_saida = df

valor_le = df$LE

valor_tr = df$TR

relacao_ts = (valor_le/valor_tr)
#------------------------------------Calculo pra Capabilidade---------------------
capabilidade_LE <- valor_le
capabilidade_LE = matrix(valor_le, nrow = 1, ncol = length(valor_le), byrow = TRUE)
normalidade_LE = matrix(valor_le, nrow = length(valor_le), ncol = 1, byrow = TRUE)


capabilidade2 <- relacao_ts
capabilidade2 = matrix(relacao_ts, nrow = 1, ncol = length(relacao_ts), byrow = TRUE)
normalidade2 = matrix(relacao_ts, nrow = length(relacao_ts), ncol = 1, byrow = TRUE)

That last part, what plot's the graph, this last part of the code needs to wait for the button to be pressed to run. Otherwise, it will generate an error.

How can I fix it?

Can you please reduce the length of code to a minimum possible that reproduces the issue?

1 Like

Thanks man! It's solved with your advice.

The acctionButton works!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.