【问题标题】:How to make reactive input in RShiny?如何在 RShiny 中进行反应输入?
【发布时间】:2019-06-08 14:37:44
【问题描述】:

如何为 data.R 代码创建输入值?

例如:

UI.R

numericInput(inputId= "diametro", label= "Diametro do Aco:", value= 0)

服务器.R

????

数据.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”值,数据库将在数据中搜索。

感谢帮助

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    另一种方法是paste() 函数。如果您需要一个输入向量(多个条件),您可以使用 paste0()collapse 参数来指示用于粘贴向量的每个元素的分隔符。

    UI.R

    numericInput(inputId= "diametro", label= "Diametro do Aco:", value= 0)
    

    服务器.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)
    )}
    

    【讨论】:

    • paste 没有 collapse 参数吗?
    【解决方案2】:

    你需要这样的东西:

    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"
      )
      )
    })
    

    【讨论】:

      猜你喜欢
      • 2018-10-22
      • 2017-11-13
      • 2021-01-06
      • 2017-10-07
      • 2020-09-13
      • 2020-09-18
      • 1970-01-01
      • 2021-03-09
      • 1970-01-01
      相关资源
      最近更新 更多