Extending RStudio with the Viewer Pane

Hi,
there is a fairly old post dated November 23, 2016, 18:20, [https://support.rstudio.com/hc/en-us/articles/202133558-Extending-RStudio-with-the-Viewer-Pane], together with a few comments and answers - and I still have the same problem described in it.

The background: I am working on a neural network in kerasR. There is an existing model and it works as expected within RStudio. The part of the program where my problem arises is the training & validation process. It looks as follows:

history <- model %>% fit( 
  x_train,
  y_train,
  batch_size = Bs,   
  initial_epoch =0, 
  epochs = trep,  
  verbose = 2,
  view_metrics = "auto",
  validation_data = list(x_val, y_val),  
  shuffle = "batch"  
)

As soon as the code suggested in the post mentioned above,

viewer <- getOption("viewer")
viewer("http://localhost:8000")

is inserted right before the line "history..." and the program is run, a message "HTTP Error 404..." appears and nothing else happens in the viewer window. If I click the button "view in new window", a new window opens in my browser, showing in real time what's going on in my application - exactly the same behavior as without the additional code. This is not only rather unpractical, since I would prefer just to look simultaneously on a listing of my ongoing process in parallel to the developing picture within the viewer pane; I also have noticed that the browser produces problems (due to limiting storage space, I suppose) when keeping several (>5) of these windows for later comparison.

To me it looks as if the address given in the second line

viewer("http://localhost:8000")

simply doesn't exist. But I have no idea as to what I could use instead of this one. Any other number instead of the '8000' produces the same result anyway. Do I have to define this address beforehand? And if so - how and where can I do that?

Just in case this might be helpful: I'm using RStudio Version 1.1.383 together with R 3.4.3.

Is this problem really still unsolved? You support would be appreciated - thanks in advance.

Leo

Hello, Leo. I'm not super familiar with Keras, but I was curious what environment you are working in. Are you on a Desktop or an RStudio server?

I just walked through the example at https://keras.rstudio.com/ and everything showed up in the viewer by default... although, I just realized that you are using kerasR, not the keras package by RStudio (get it with remotes::install_github("rstudio/keras"). In any case, I definitely recommend checking out the latter, as it has a great API and functionality IMHO!

Essentially, what seems to be happening (if kerasR is indeed exposing a service on localhost:8000 - is that the URL that you use in the browser??) is that calling the URL before the service is available gives you a 404. It might be worth clicking the "Refresh" button in the top right corner of the viewer once the service is up and see if that helps!

Hi,-
thanks for your reply - and excuse my late coming back to it. It was the first time ever somebody replied to one of my requests in this forum and I probably overlooked the notification.

I'm using both kerasR and keras on my desktop RStudio under WIN10. What I noticed only recently is that the viewer automatically shows the real time events as required, however, only for epochs<10 (!). As soon as I specify more than 9 epochs in the fit()-proecedure shown in my initial post, upon klicking the button "View in new window" above the Viewer pane, the display appears, but in my browser only, never in the Viewer pane.

Thus my actual impression is, the whole problem is one of default settings of the RStudio-Viewer. The question remains therefore, where could I influence these settings? I didn't find any indication whatsoever.

Any advice on that by you or somebody else reading this post would be most gratefully acknowledged!

Cheers,
Leo

Just curious, since your example above uses kerasR, do you encounter the issue with the kerasR package or the keras package? Both? Do you think you could try to provide a reprex so that others can try to see the behavior on their own system? (i.e. in your previous example, model is not available on my system, for instance).

Hi,-
thanks for reply. I can't tell which of keras or kerasR I am (or my programs are) actually using, as I have to call both of them - always. In each of my programs, I call them by library(keras) and library(kerasR); I got the impression they "need each other", neither can do without the other. Btw, I have keras v2.1.1.9001 and kerasR v0.6.1 installed.

Creating a reprex in this post proved a problem in itself, as I got the following error message when installing and using reprex() exactly as indicated (sorry about all that):

reprex()
Rendering reprex...
Error in r(func, args = args, libpath = libpath, repos = repos, cmdargs = cmdargs, :
unused argument (spinner = TRUE)

So, in order to proceed to my initial problem, I just provide a copy of a short NN-program example which exhibits exactly the behaviour I described in my previous posts:

library(kerasR)
library(keras)
model <- keras_model_sequential() %>%
layer_dense(units = 32, activation = "relu", input_shape = c(64)) %>%
layer_dense(units = 32, activation = "relu") %>%
layer_dense(units = 10, activation = "softmax")

model %>% compile(
optimizer = "rmsprop",
loss = "categorical_crossentropy",
metrics = c("accuracy")
)

x_train <- array(runif(1000 * 64), dim = c(1000, 64))
y_train <- array(runif(1000 * 10), dim = c(1000, 10))

model %>% fit(
x_train,
y_train,
epochs = 10, # exchange to <10 to initiate a real-time display in viewer pane!
batch_size = 128,
verbose = 2,
view_metrics = "auto",
validation_split = 0.2)

If I run this program as is (i.e. epochs=10 or greater), the viewer pane gets empty and then, by clicking "View in new window" I am able to look at the real time proceedings in my browser only. For epochs=9 or lower, the display starts immediately in the viewer pane as I would like it to in any other case, too.

Looking forward,
Leo