SQL syntax issues with glue and shiny

Split from Error in WHERE Syntax using GLUE package


Other question!

If i create this input:

checkboxGroupInput("ordemlista", "Tipo de Ordem:",
                                           choices=list('LQ','LQR', 'LQX')
                               ),

To filter using the choises with LIKE condition, how can I do?

select cod_ordem_producao
from pla.cod_ordem_producao
WHERE cod_ordem_producao like '{input$ordemlista}'% <----- DOES NOT WORK

In my SQL code, I can do it directly, that way: (for example)

select cod_ordem_producao
from pla.cod_ordem_producao
WHERE cod_ordem_producao like 'LQR%'

But using GLUE package with the INPUT, it just not work.

Does someone know how to fix?

When using glue, you always have to access values from the R session with braces

'{input$ordemlista}'
1 Like

I did it and just did not work.

I just forget to put the braces in my post, but I already edited.

O think the '%' is the problem with this syntax.

With this code '{input$ordemlista}'%you are getting 'LQR'% and you need `'{input$ordemlista}%' ----> 'LQR%' do you see the difference?

I tried

WHERE cod_ordem_producao like '{input$ordemlista}%'

but it still not working for the search of the string with the INPUT SELECT.
It just not return what is the error.

This produces the right sql query for me

library(shiny)
library(glue)

ui <- fluidPage(
    
    checkboxGroupInput("ordemlista", "Tipo de Ordem:",
                       choices=list('LQ','LQR', 'LQX')
    ),
    
    tableOutput(outputId = "query")
)

server <- function(input, output) {
    output$query <- renderText({
        glue("select cod_ordem_producao
             from pla.cod_ordem_producao
             WHERE cod_ordem_producao like '{input$ordemlista}%'")
    })
}

shinyApp(ui = ui, server = server)

but only works if you choose just one choice, I think a checkbox is not a good idea here.

2 Likes

Thanks! Solved using that way.
The mistake was in ' and " that mixed in the code.
xD. Thx for the time, friend.

This topic was automatically closed 54 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.