Watson Conversation + R

Watson Conversation + R

Update 10/20/2018: IBM changed something on their api that broke my package. I might try to fix this at some point, for now you can take a look at the video bellow.

I just discovered IBM’s Watson conversation, and this free online course shows you how to build your first chatbot. Alas, the course did not cover how to use the API with R.

I think chatbots can be very useful when creating shiny apps. Therefore, I started working on IMWatson. The goal of this R package is to make integrating a chatbot into a shiny app as easy as possible.

To install it:

drat::addRepo(account = "Ignacio", alturl = "https://drat.ignacio.website/")
install.packages("IMWatson")

To add it to your shiny app you only need to use the included shiny module:

## app.R ##
library(shiny)
library(shinydashboard)
library(IMWatson)
ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(IMWatson::chatbotUI("watson"))
)
server <- function(input, output, session) {
  callModule(IMWatson::chatbot, "watson", username = IMSecrets::watson_conversation()$usr,
             password = IMSecrets::watson_conversation()$pwd,
             workspace = IMSecrets::watson_conversation()$RCE)
}
shinyApp(ui, server)

I also included a shiny app that contains only the chat bot:

ShinyChatbot(username = IMSecrets::watson_conversation()$usr,
password = IMSecrets::watson_conversation()$pwd,
workspace = IMSecrets::watson_conversation()$RCE)

And the ability to creat a chatbot directly without shiny:

library(IMWatson)
chatbot <- watson_chat_factory$new(IMSecrets::watson_conversation()$usr,
                                   IMSecrets::watson_conversation()$pwd,
                                   IMSecrets::watson_conversation()$RCE)
chatbot
## <b>Chatbot:</b> Hello. I'm the RCE Coach chatbot. How would you like me to call you?
chatbot$answer('Ignacio')
chatbot
## <b>Chatbot:</b> Hello. I'm the RCE Coach chatbot. How would you like me to call you?
## <b>You:</b> Ignacio
## <b>Chatbot:</b>
chatbot$context
## {}

Video talking about this

Ignacio Martinez avatar
About Ignacio Martinez
research economist, tech enthusiast
comments powered by Disqus