Splunk Dev

Cannot display the Plot from R on splunk

harshal_chakran
Builder

Hi,

I have integrated "r" (splunk app) with R and i am trying to run the following script

beta_binom<-function(n,y,a=1,b=1,main="")
{
    #likelihood: y|theta~binom(n,theta)
    #prior: theta~beta(a,b)
    #posterior: theta|y~beta(a+y,n-y+b)

theta<-seq(0.001,0.999,0.001)
prior<-dbeta(theta,a,b)
if(n>0){likelihood<-dbinom(rep(y,length(theta)),n,theta)}
if(n>0){posterior<-dbeta(theta,a+y,n-y+b)}

#standardize!
prior<-prior/sum(prior)
if(n>0){likelihood<-likelihood/sum(likelihood)}
if(n>0){posterior<-posterior/sum(posterior)}

ylim<-c(0,max(prior))
if(n>0){ylim<-c(0,max(c(prior,likelihood,posterior)))}

plot(theta,prior,type="l",lty=2,xlab="theta",ylab="",main=main,ylim=ylim)
if(n>0){lines(theta,likelihood,lty=3)}
if(n>0){lines(theta,posterior,lty=1,lwd=2)}
legend("topright",c("prior","likelihood","posterior"),
       lty=c(2,3,1),lwd=c(1,1,2),inset=0.01,cex=.5)

}

The plot is working fine on R , but we are unable to figure how to get the plot on Splunk via 'r' splunk app.

We executed the following command on splunk after uploading the above script using the example given on the app

| r "
source('trial1.r')
result = beta_binom(4,2,5,10,"")
output = data.frame(Result=c(result))
"

and we got following output

alt text

alt text

and the same script when run on R, it gives following output, please help

alt text

1 Solution

rfujara_splunk
Splunk Employee
Splunk Employee

You are correct, it's not possible to use the R plot function to display charts in Splunk.

So you need to output data to Splunk (you've already done that) and pipe the data to a chart command. Like this:

| r "..." | chart ...

See documentation of the chart commend here and here.

The screenshot you posted shows four plotted charts. I think the Splunk chart command supports only one chart. To display fours charts at the some time, you need to create a dashboard containing fours panels each contains one chart. See documentation about creating dashboards here.

I don't know what kind of math function you use to plot those kind of charts and I don't know if there is a equivalent function/command to create charts that looks the same. Maybe have a look at the list of supported commands.

View solution in original post

SanthoshSreshta
Contributor

Try this

| r "
 source('trial1.r')
 result = beta_binom(4,2,5,10,"");
 output = data.frame(Result=c(result))
 "

just use ; delimiter before the output command.

0 Karma

rfujara_splunk
Splunk Employee
Splunk Employee

You are correct, it's not possible to use the R plot function to display charts in Splunk.

So you need to output data to Splunk (you've already done that) and pipe the data to a chart command. Like this:

| r "..." | chart ...

See documentation of the chart commend here and here.

The screenshot you posted shows four plotted charts. I think the Splunk chart command supports only one chart. To display fours charts at the some time, you need to create a dashboard containing fours panels each contains one chart. See documentation about creating dashboards here.

I don't know what kind of math function you use to plot those kind of charts and I don't know if there is a equivalent function/command to create charts that looks the same. Maybe have a look at the list of supported commands.

Get Updates on the Splunk Community!

AppDynamics Summer Webinars

This summer, our mighty AppDynamics team is cooking up some delicious content on YouTube Live to satiate your ...

SOCin’ it to you at Splunk University

Splunk University is expanding its instructor-led learning portfolio with dedicated Security tracks at .conf25 ...

Credit Card Data Protection & PCI Compliance with Splunk Edge Processor

Organizations handling credit card transactions know that PCI DSS compliance is both critical and complex. The ...