如何为data.R代码创建输入值?
例如:
UI.R
numericInput(inputId= "diametro", label= "Diametro do Aco:", value= 0)
Server.R
????
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 diametro = **_THE INPUT VALUE FOR DIAMETRO HERE_**
order by DTH_CRIACAO_REG desc"
df <- dbGetQuery(
connection_reportUser,
query
)
df```
我无法为此创建反应性值。 用户将在数字小工具中输入“ diametro”值,数据库将在数据中搜索该值。
寻求帮助
答案 0 :(得分:2)
另一种方法是paste()
函数。如果您需要一个输入向量(多个条件),则可以将paste0()
与collapse
参数一起使用,指示用于粘贴向量的每个元素的分隔符。
UI.R
numericInput(inputId= "diametro", label= "Diametro do Aco:", value= 0)
Server.R
library(RMySQL)
library(shiny)
getQuery <- reactive({
query <- paste("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 diametro = ",
input$diametro,
" order by DTH_CRIACAO_REG desc",
sep="")
df <- dbGetQuery(con, query)
return(df)
)}
答案 1 :(得分:0)
您需要这样的东西:
library(shiny)
library(dplyr)
library(glue)
df <- eventReactive(input$diametro,{
connection_reportUser %>% dbGetQuery(
glue::glue( "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 diametro = {input$diametro}
order by DTH_CRIACAO_REG desc"
)
)
})