在我闪亮的仪表板中,我生成了复杂的SQL,它从用户那里获取输入并生成SQL代码并在用户输入用户名/密码后执行它。
我在UI.R中生成一个htmlOutput,以在代码运行之前显示代码。
当显示为textOutput时,代码包含换行符 br(), em()和 shiny-html-output div中包含的注释 elements。
我的目标是能够使用htmlOutput作为sqlQuery函数的输入。
SERVER.R的部分
qry_SQL <- reactive({tempfunc(1, "TD")})
# tempfunc creates my SQL using inputs present in UI.R
output$qry_out_text <- renderText(qry_SQL())
#Generates output in text format that contains <br/>, <em> and <div id="key1A_main_TD_1" class="shiny-html-output"> elements
output$qry_out_text2 <- renderUI(qry_SQL())
# Generates html output that I would ideally like to pass to sqlQuery
output$qry_out <- renderDataTable({
input$Execute
validate(
need(input$Username!=""&&input$Password!="","Please input Username and Password for TERADATA"),
need(input$Execute>0,"Click Execute")
)
ch <- odbcConnect(dsn="CustomDSN",uid=input$Username, pwd = input$Password)
import <<- sqlQuery(ch, PASS_HTML_OUTPUT_HERE, errors = FALSE )
odbcClose(ch)
head(import, n =100)
})
理想情况下,我需要帮助您在上面的 PASS_HTML_OUTPUT_HERE 块中输入内容。
使用textOutput输出时,qry_SQL()会产生以下结果:
SELECT c1.COL1, c1.COL2
FROM TABLE as c1
WHERE cast(c1.DateNow as date) between '2015-09-19' and '2015-10-16'
and <div id="key1A_main_TD_1" class="shiny-html-output"></div>
<div id="key2A_main_TD_1" class="shiny-html-output"></div>
<div id="key3A_main_TD_1" class="shiny-html-output"></div>
<div id="key4A_main_TD_1" class="shiny-html-output"></div>
<div id="key5A_main_TD_1" class="shiny-html-output"></div>
在这种情况下,key1A_main_TD_1产生“(AND c1.Details like'%unhappy%')” 其他div标签不会产生任何结果,因为用户没有输入任何内容。
当使用htmlOutput输出时,qry_SQL()会产生以下结果:
SELECT c1.COL1, c2.COL2
FROM TABLE1 as c1
WHERE cast(c1.DateNow as date) between '2015-09-19' and '2015-10-16'
and
(c1.Details like '%unhappy%')
我的问题是我希望将qry_SQL()作为HTML传递,并解析div标签。
干杯, 阿南德