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, make a U-turn, 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 pUTurn <- input$pUTurn pStraight <- 1 - pLeft - pRight - pUTurn prob <- c(pLeft, pRight, pStraight, pUTurn) #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({ pStraight <- 1 - input$pLeft - input$pRight - input$pUTurn print(c('Prob. of going straight through the intersection: ', pStraight)) }) }