如何在Rshiny网页中使用sql查询作为输出

如何在Rshiny网页中使用sql查询作为输出,r,shiny,rstudio,dbi,sparklyr,R,Shiny,Rstudio,Dbi,Sparklyr,因此,我试图将查询输出到Rshiny应用程序,但输出中不断出现错误。以下是我的输出: # # This is a Shiny web application. You can run the application by clicking # the 'Run App' button above. # # Find out more about building applications with Shiny here: # # http://shiny.rstudio.com/ #

因此,我试图将查询输出到Rshiny应用程序,但输出中不断出现错误。以下是我的输出:

#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

    library(shiny)
    library(DBI)

 for Spark 2.1.X
Sys.setenv(SPARK_HOME="/opt/cloudera/parcels/SPARK2/lib/spark2/")
Sys.setenv(SPARK_HOME_VERSION="2.1.0")


#Connecting to Spark
sc <- spark_connect(master ="yarn-client")

ui <- fluidPage(
  numericInput("nrows", "Enter the number of rows to display:", 5),
  tableOutput("tbl")
)

server <- function(input, output, session) {
  output$tbl <- renderTable({

    iris_preview <- dbGetQuery(sc,"select * from sndbx_dx.ncct_mapping limit 3")
    iris_preview

  })
}

shinyApp(ui, server)
#
#这是一个闪亮的web应用程序。您可以通过单击来运行应用程序
#上面的“运行应用程序”按钮。
#
#在此处了解有关使用Shining构建应用程序的更多信息:
#
#    http://shiny.rstudio.com/
#
图书馆(闪亮)
图书馆(DBI)
对于Spark 2.1.X
Sys.setenv(SPARK_HOME=“/opt/cloudera/parcels/SPARK2/lib/SPARK2/”)
系统设置环境(SPARK\u HOME\u VERSION=“2.1.0”)
#连接到火花

sc以下是一个基于iris数据集和sqlite的简单示例:

library(shiny)
library(RSQLite)
library(DBI)
library(datasets)

con <- dbConnect(RSQLite::SQLite(), ":memory:")
dbWriteTable(con, "iris", iris)
dbListTables(con)

ui <- fluidPage(
  numericInput("nrows", "Enter the number of rows to display:", 5),
  actionButton(
    inputId = "queryButton",
    label = "Query",
    icon = icon("refresh")
  ),
  tableOutput("tbl")
)

server <- function(input, output, session) {
  iris_preview <- reactiveVal(data.frame())

  observeEvent(input$queryButton, {
    queryString <- sprintf("select * from iris limit %s", input$nrows)
    iris_preview(dbGetQuery(con, queryString))
  })

  output$tbl <- renderTable({
    iris_preview()
  })
}

shinyApp(ui, server)
库(闪亮)
图书馆(RSQLite)
图书馆(DBI)
图书馆(数据集)

我可以很快和你聊一聊吗?我有几个问题。请并感谢您当然,请随意提问。如何显示多个查询字符串?因此,如果我想显示另一个表,我是否可以复制并粘贴带有不同select子句的observeEvent部分?请在联机时通知我,我将设置聊天。要显示另一个表,您需要一秒钟的时间