本文介绍了运算符对原子向量无效 将数据从 SQL 导入到闪亮的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用 (RODBCext) 从 SQL Server 获取原始数据,然后将结果部署到我的 ShinyApp这是我的代码:
I try to get my raw data from SQL Server using (RODBCext) and then deploy my results to my shinyAppthis is my code:
#loading Packages
library(RODBC)
library(shiny)
library(rsconnect)
library(dplyr)
library(RODBCext)
#global code
#connect to DB
Test <- odbcDriverConnect("driver={SQL Server};server=***********;database=*******;uid=*****;pwd=******")
#build query
Orders<- sqlExecute(Test,"
SELECT
WHWorkOrderHeaderId
,OtherLangDescription
FROM Warehouse.WHWorkOrderDetails
INNER JOIN Warehouse.WHWorkOrderHeader AS WHH
ON Warehouse.WHWorkOrderDetails.WHWorkOrderHeaderId = WHH.ID
INNER JOIN Warehouse.StockItems
ON Warehouse.WHWorkOrderDetails.StockItemId = Warehouse.StockItems.Id
WHERE Type = 'IO'
ORDER BY OtherLangDescription ASC")
#close the connection
odbcClose(Test)
#return results
Orders$OtherLangDescription <- as.factor(Orders$OtherLangDescription)
orderList <- unique(Orders$OtherLangDescription)
ListId <- lapply(orderList, function(x) subset(Orders, OtherLangDescription == x)$WHWorkOrderHeaderId)
Initial_Tab <- lapply(ListId, function(x) subset(Orders, WHWorkOrderHeaderId %in% x)$OtherLangDescription)
Correlation_Tab <- mapply(function(Product, ID) table(Product)/length(ID),Initial_Tab, ListId)
colnames(Correlation_Tab) <- orderList
cor_per<- round(Correlation_Tab*100,2)
DF<-data.frame(row=rownames(cor_per)[row(cor_per)],
col=colnames(cor_per)[col(cor_per)], corr=c(cor_per))
DF
#ui.R code
ui <- fluidPage(
titlePanel("Item Correlation"),
sidebarPanel(
selectInput("Item","Select Item",choices= DF$FirstItem),
# ,selectInput("Item","SelectItem",choices= DF$SecondItem),
),
mainPanel(
tableOutput("Itemcorr")
)
)
#server.R code
server <- function(input,output){
data<- reactive({
input$Item
})
output$Itemcorr <- renderTable({
DF %>% filter(FirstItem == data()) %>% arrange(desc(X.Correlation))
})
}
shinyApp(ui, server)
我想直接从 SQL 获取我的数据而不导出到 excel但是当我运行我的 Shinyapp 时出现错误(Orders$OtherLangDescription 中的错误:$ 运算符对原子向量无效)
i want to get my data from SQL directly without exporting to excel But i have an error when i run my shinyapp (Error in Orders$OtherLangDescription : $ operator is invalid for atomic vectors)
推荐答案
我通过将 sqlExecute 替换为 sqlQuery
这篇关于运算符对原子向量无效 将数据从 SQL 导入到闪亮的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!