Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Splunk Dev

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Splunk Answers
- :
- Using Splunk
- :
- Splunk Dev
- :
- Cannot display the Plot from R on splunk

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark Topic
- Subscribe to Topic
- Mute Topic
- Printer Friendly Page

- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

harshal_chakran

Builder

06-19-2014
02:32 AM

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

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

1 Solution

- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

rfujara_splunk

Splunk Employee

06-20-2014
05:09 AM

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.

- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

SanthoshSreshta

Contributor

07-01-2015
10:12 PM

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.

- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

rfujara_splunk

Splunk Employee

06-20-2014
05:09 AM

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!

Calling all cybersecurity professionals! The latest addition to the Splunk certification family is here, and ...

In July, the Splunk Threat Research Team had 3 releases of new security content via the Enterprise Security ...

REGISTER NOW!Tech Talk: Security EditionWednesday, August 28, 2024 | 11AM PT / 2PM ETIt’s time to accelerate ...