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.

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...