Watson Conversation + R

Watson Conversation + R
Page content

Update 03/30/2019: IMWatson is working again!

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:

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", 
             api_key = datawizard::data_wizard_secrets()$api_key, 
             workspace = datawizard::data_wizard_secrets()$workspace)
}
shinyApp(ui, server)

And the ability to creat a chatbot directly without shiny:

library(IMWatson)
chatbot <- IMWatson::watson_chat_factory$new(api_key = datawizard::data_wizard_secrets()$api_key, 
                                             workspace = datawizard::data_wizard_secrets()$workspace)
chatbot
## <b>Chatbot:</b> Hello. I'm Ignacio's Data Wizard chatbot. How would you like me to call you?
chatbot$answer('Ignacio')

chatbot
## <b>Chatbot:</b> Hello. I'm Ignacio's Data Wizard chatbot. How would you like me to call you?
## <b>You:</b> Ignacio
## <b>Chatbot:</b> Hi Ignacio. I can help you craft your research question. If you already have a question, I can help you determine you approach. What would you like to do?
chatbot$context
## {"conversation_id":"d34441fa-261b-4026-8f1e-feaddb3dc393","system":{"initialized":true,"dialog_stack":[{"dialog_node":"root"}],"dialog_turn_counter":2,"dialog_request_counter":2,"_node_output_map":{"Welcome":0,"node_23_1507666135810":0},"branch_exited":true,"branch_exited_reason":"completed"},"username":"Ignacio"}

Video talking about this