cytoscape / cyjShiny

An R/shiny widget for cytoscape.js
Other
92 stars 28 forks source link

learn R6 unitTest idiom by evolving from minimal helloWorld shiny app #47

Closed paul-shannon closed 2 years ago

paul-shannon commented 3 years ago

@Dharna5599,

As we discussed, your goal is to acquire complete familiarity with the R6 unitTest strategy used in unitTests/test_selection.R. There is quite a lot to grasp here, and it must be grasped deeply for you to add the large number of feature-by-feature unitTests for cyjShiny we need for package submission.

The plan:

  1. write the simplest possible, traditionally structure shiny app: one button, on HtmlOutput, click the button, "Hello, World!" appears in the html output.
  2. once I sign off on that, then embed that working code into the R6 structure in test_selection.R - but DO NOT add tests yet! the sub-goal here is simply to make you completely at home with R6 classes. Read up on their design. Hadley does a good job in his book.
  3. Next, study up on later which is an indispensable tool for testing shiny's asynchronous behavior.
  4. With all this as solid ground, once you are deeply familiar with all you have written, and the background reading is complete, we will discuss testing strategies, including the use of a private class variable to record your R6 object's state.
Dharna5599 commented 3 years ago

Hey @paul-shannon , I have worked on your 1st plan..please look at this directory on inst/unitTests/Hello_world.R

paul-shannon commented 3 years ago

@Dharna5599 - a good start. Here are some suggestions.

Remove most of the white space. For instance, the blank line between the two widget constructors in the ui. Use names which are descriptive, and camel case rather than underscores. rather than, "Print_Hello", I suggest "printHelloButton" rather than "Server_Hello", "textDisplay"

# Run the application tells us nothing we do not already know.

In order for me tor run the app in plain R (I never use RStudio) I had to change your code:

 runApp(shinyApp(ui = ui, server = server))

Please find a way to invoke the app which does not depend upon RStudio (but that still works conveniently for you within RStudio)

Dharna5599 commented 3 years ago

@paul-shannon, thank you for the suggestion..I will surely look upon that.

Dharna5599 commented 3 years ago

Hey @paul-shannon, I made the necessary adjustments and embedded code in the R6 structure. Kindly have a look at the same directory inst/unitTests/Hello_world.R.

paul-shannon commented 2 years ago

@Dharna5599 I just pushed inst/demos/simple_R6_shiny.R for you to study.

paul-shannon commented 2 years ago

@Dharna5599 - good zoom meeting just now. Thank you. Two coding strategies (maybe "meta-strategies"):

  1. develop your code incrementally, just one new feature at a time( one new line, or block of code, or function, or shiny widget). Be humble, be pessimistic, expect things to fail, due to a small problem, or maybe a large conceptual problem
  2. when a new feature does not work, then EXTRACT that feature, and the puzzle it presents, work on it SEPARATELY, in a minimal context, the simplest possibly setting in which you can reproduce and study the puzzle

Your tasks - to be implemented using these two strategies:

  1. add a new (a third) button to simple_R6_shiny.R, labeled "display current value". do NOT write a handler for that yet
  2. add a first output widget to the app, "textDisplayOutput" using the verbatimTextOutput shiny widget
  3. wrap the verbatimTextOutput widget in a div, with a style which specifies height, width, and a colored border - so that we can see that this appears in the ui

Important:

  1. precede pessimistically, humbly, assuming things will go wrong
  2. do not add any event handlers to the server. This task concerns only the ui - the html which shiny will generate for you

After I approve your changes, we will move in this same incremental, pessimistic and humble way to add event handlers.

Then we will add tests.

Remember that the best way to get somewhere fast is to go slowly!

Dharna5599 commented 2 years ago

@paul-shannon thankyou soo much Sure I will do it.

Dharna5599 commented 2 years ago

Hey @paul-shannon, I have pushed the required code for the given task. Please have a look at it.

paul-shannon commented 2 years ago

No changes in simple_R6_shiny.R!

On Jul 30, 2021, at 7:39 AM, Dharna Chandrakar @.***> wrote:

Hey @paul-shannon, I have pushed the required code for the given task. Please have a look at it.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

Dharna5599 commented 2 years ago

Can you please recheck, I missed the commit. Sorry for inconvenience!

paul-shannon commented 2 years ago

Looks good, @Dharna5599! Now we want the textOutputDisplay to always display private$currentValue.

At the start of the program, it will display a zero. With every click of the incrementValueButton, textOutputDisplay will update to display the newly incremented value.

Some questions and suggestions (and thinking out loud):

  1. can shiny observe private$currentValue? I am not sure
  2. will you need to create a reactive value, which depends upon private$currentValue?

read and experiment! Let me know what you figure out, and what is confusing.

Dharna5599 commented 2 years ago

Sure @paul-shannon, I will. Thankyou

Dharna5599 commented 2 years ago

Hey @paul-shannon, As you suggested, I tried and experimented with the code and discovered that shiny observes the private$currentValue, thus we don't need to create reactive values in this instance. Thus I have pushed the updated version of code in github and on starting the program, it just displays zero. Perhaps on clicking the incrementValueBtton, the textOutputDisplay gets updated. Kindly have a look at it and if I misunderstood something please let me know.

Thank you Dharna

paul-shannon commented 2 years ago

@Dharna5599 - let's tentatively close this issue, based on your good work inst/demos/ simple_R6_shiny.R. We can re-open if necessary.

Please move on to the new issue I am about to create - automated testing for the cyjShiny function selectFirstNeighbors .