library(shiny) library(docstring) source("drive.R") problemStatement <- "This is a simulation of a car driving in a city and taking random \ turns left, right, or not turn at all, with some probabilities \ which can be adjusted with the sliders. If we do not turn, we continue \ in the same direction we came from." function(input, output) { output$problemStatement <- renderText(problemStatement) output$pathPlot <- renderPlot({ input$goButton nturns <- input$nturns nblocks <- input$nblocks pLeft <- input$pLeft pRight <- input$pRight pStraight <- 1-pLeft-pRight prob <- c(pLeft, pRight, pStraight) print(c('Prob: ',prob)) tryCatch({ drive(nturns, nblocks, prob) }, error = function(cond) { plot(NULL,xlim=c(-nblocks,nblocks),ylim=c(-nblocks,nblocks)) text(0, 0,'Probability of no-turn dropped below 0',col=2,cex = 2) }) }) output$pStraight <- renderText({ pLeft <- input$pLeft pRight <- input$pRight pStraight <- 1-pLeft-pRight print(c('Prob. of going straight through the intersection: ', pStraight)) }) }