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.

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

Data Management Digest – May 2026

Welcome to the May 2026 edition of Data Management Digest!   As your trusted partner in data innovation, the ...