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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...