Erdem Akkas
Erdem Akkas

Reputation: 2060

How to check if Shiny app is running on a specific ip and address?

I have a shiny app which runs on a specific ip address and port.

shiny_start_script.R

runApp(host = myhost, port = myport)

I would like to have another R script which frequently checks if that shiny app is live.
By this way, if it is terminated for some reason the script can run above runApp command.

How can I accomplish that?

Upvotes: 0

Views: 737

Answers (1)

maydin
maydin

Reputation: 3755

I am using very similar script to make my shiny app be working always by the power of the windows task scheduler.

Here is the script you can run,

library(httr)
library(shiny)

url <- "http://....." # your url or ip adress

out <- tryCatch(GET(url), error = function(e) e) # To find if your url working or not
logic  <- any(class(out) == "error") # returns TRUE/FALSE due to the existance of an error

   # The codes below stands for rerunning the main script if there exists an error.

if(logic) {

Sys.sleep(2)

wdir <- "your_working_directory"
setwd(wdir)

require(shiny)

x <- system("ipconfig", intern=TRUE)
z <- x[grep("IPv4", x)]
ip <- gsub(".*? ([[:digit:]])", "\\1", z)

source("./global.R")

runApp(wdir , launch.browser=FALSE, port = myport , host = ip)


}

After saving the script. Say "control.R", the very next thing you should do is setting a windows task scheduler to run this script. In this question you can find information about this.

Upvotes: 1

Related Questions