aoles / EBImage

:art: Image processing toolbox for R
70 stars 28 forks source link

Added Shiny.setInputValue() in a few places to make some variables av… #37

Open jkh1 opened 5 years ago

jkh1 commented 5 years ago

…ailable to Shiny app.

jkh1 commented 5 years ago

This partly addresses issue #33.

aoles commented 5 years ago

Thanks a lot!

I will get back to you as soon as I have reviewed your code.

Cheers, Andrzej

mattwarkentin commented 5 years ago

@jkh1 Should using this version of the viewer.js file in place of the original file that installs by default provide the relevant variables simply when calling the Viewer in R/RStudio using EBImage::display(x)? Or does one need to integrate Shiny in some way? I am new to all things Shiny so forgive my ignorance.

jkh1 commented 5 years ago

@warkentinmatt Yes, this can be used as a drop-in replacement. You then access the variables in the usual Shiny way with input$variable_name, e.g. input$pixelPosition.

mattwarkentin commented 5 years ago

@jkh1 Thank you for your response.

So I have tried to drop-in this javascript file and it does not seem to be working as anticipated. You say it should work "in the usual Shiny way", perhaps this is where I am falling short. What does this mean? My expectation was that after replacing the viewer.js file, that when I call EBImage::display(x) in RStudio, that I would be able to click a specific pixel and access its value by calling input$pixelPosition interactively in the console. Is this an incorrect expectation? Where does Shiny fit in?

Thank you for your help.

jkh1 commented 5 years ago

Shiny is a web framework so I don't quite see where the console comes in. I've only used Shiny to create web-based apps. If this is a more generic Shiny programming problem, it might be better addressed on StackOverflow.

chrisjw18 commented 5 years ago

Thanks for this update its exactly what I have been looking for to aid in identifying objects within images ( in a round about way). I've changed the viewer.js file and added an observe() event in the server side of my shiny app to monitor the variable input$pixelPosition but unfortunately it doesn't seem to be providing input either automatically or when clicking the mouse over the image. Is there a way to test the input variable is available server side? I have tried wrapping this in observe(), reactive() and observeEvent(input$pixelPosition,{}) with a simple call to print(input$pixelPosition) to highlight if it is working.

Any help would be greatly appreciated.

jkh1 commented 5 years ago

The way I do it is with:

rv <- reactiveValues(pixelPosition = NULL)
observe({ rv$pixelPosition <- input$pixelPosition })

Then you can access it from rv$pixelPosition in the rest of the server code. You can see it in action in our Image Data Explorer (look in the file image_data_explorer.R). By the way, the Image Data Explorer may already be doing some of what you want.

chrisjw18 commented 5 years ago

Third attempt to reply properly>

Many thanks for the quick reply - afraid it is still not working. I have found a way to print all available inputs to console when my app is running and pixelPosition is not listed. The Image Data Explorer looks brilliant and after reviewing the script I think I am trying to read in pixel values from an image constructed in the same way to your app, i.e. load image and use displayOutput ui side to display image using the EBImage package.

My app is much more simple than yours and I'm very new to shiny (and GitHub). If you have the chance to review my script with regard to the pixelPosition aspect it would be greatly appreciated. I have attached it here as a.txt file but it is a R file (seems GitHub doesn't support .R files) and an example image should also be attached. The relevant pieces of text are located at the very end of the server function (very bottom of the script), and I am trying to get the x/y pixel locations from output$img1 which is shown in the main plotting image on the first tab once an image has been uploaded.

Apologies for the untidiness of my script - it is a serious work in progress.

Many Thanks,

Chris. shiny_script_txt.txt 2018_mixed_samples_1_bak

chrisjw18 commented 5 years ago

Further to my last post - I decided to check this at home on my Ubunto system (as opposed to my mac at work) and it works fine, so I dont know why this isnt currently working on my mac. It might be due to failure to override the standard EBImage package, so I will manually delete and reinstall the amended package from your github and see how it goes.

chrisjw18 commented 5 years ago

Yes, that was the issue. I've now (properly) re-installed the updated EBImage from your GitHub and it is working perfectly. Thank you very much.

Chris.