因此,我试图将查询输出到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)
我只是想让Iris_preview在运行时显示在闪亮的应用程序中。有人看到我在做什么错吗?
自从我连接到spark以来,我想从Hive数据库中输出表。
答案 0 :(得分:1)
这是一个基于虹膜数据集和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)
从长远来看,请阅读this。