為什麼需要使用R引擎將StreamBase整合到SpotFire?

2021-08-27

Nithish Thirmul Picture
Nithish Thirmul, Posted on June 20, 2019 StreamBase To SpotFire Integration Using R

SpotFire和Streambase是TIBCO熱銷產品之一。前者處理的是資料分析、儀表板等等,後者處理的是即時串流資料。

為什麼兩者之間需要被整合?

將即時資料和歷史資料整合,企業用戶可以對現在和過去的資料分析做出即時有效的決策。

這篇文旨在介紹透過使用R引擎將資料從StreamBase傳送到SpotFire來實現這兩者之間的整合。

替代方法:

為此,已經有替代方法,在StreamBase中使用DataBase或使用Apache Spark等等的一些連接器。

但在這篇文中,我們純粹只需要一個使用R 腳本作為媒介的解決方案。 讓我們一步一步來達成案例。

第一步:建立StreamBase項目

先建立一個簡單的StreamBase項目,在應用程式處理過程中,在輸入流中建立3個參數,分別是name、age和city。

name – string age – int city – string


建立輸入參數

將輸入參數傳送至TERR,最終會傳送到SpotFire 在TERR中使用以下腳本:


在TERR中編寫R代碼

StramBase TERR R Script:

#load the libraries

library(RinR)

library(Sdatasets)

#Set the working Directory and execute in Below R Engine path

RinR::pushPATH(“C:/Program Files/R/R-3.3.1/bin”)

REvaluate(version$version.string, REvaluator)

setwd(“C:/Users/Nithish/Documents”)

iris.env<- environment()

#Create a Rdata at the backEnd. ( Initially it will be empty) and load the RData dd<-load(“C: /Users/Nithish/Documents/import.RData”, envir=iris.env) iris.imp<-iris.env$lvspf

#Assign the name,age city to variables a,b,c

a <- $[name]

b <-$[age]< /p>

c <- $[city]

#Create a data frame for a,b,c

newdata<- data.frame(a,b,c)

lvspf <- rbind(iris.imp,newdata)

#Update the Rdata file

save(lvspf, file=”import.Rdata”)

第二步:建立Spotfire項目並整合Streambase資料

開啟Tibco SpotFire並建立R腳本導入Streambase項目中所使用的Rdata。


在R引擎中建立數據函數

SpotFire DataFunction Properties Script (Spotfire數據函數屬性腳本):

#Upload the library and set the R Environment

library(RinR)

library(Sdatasets)/p>

RinR::pushPATH(“C:/Program Files/RStudio/bin”)

REvaluate(version$version.string, REvaluator)

#set the working Directory and load the RData file

setwd(“C:/Users/Nithish/Documents”)

iris.env <- environment()

dd <- load(“C:/Users/Nithish/Documents/import.RData”,envir=iris.env)

lvspf12345 <- iris.env$lvspf

在相對應數據函數的“編輯參數”中,將輸出建立為表格。


編輯數據參數

點擊OK並查看建立的表格。要更新或重新整理在StreamBase被建立的新數據,點擊Refresh (在Spotfire的文本區建立一個重新整理函數,它會在每次點擊時引用數據函數)。

測試場景:

  • 啟動StreamBase項目,輸入name、age、city參數。以下提供兩個數據:1. Rooney , 35 , Manchester 2. Pogba , 24 , Manchester

  • 在Spotfire中點擊重新整理按鈕並查看表中新增項目。