ctmm-initiative / ctmmweb

Web app for analyzing animal tracking data, built upon ctmm R package
http://biology.umd.edu/movement.html
GNU General Public License v3.0
34 stars 22 forks source link

work report - record every meaningful action; save and restore session #34

Closed xhdong-umd closed 7 years ago

xhdong-umd commented 7 years ago

There will be console messages like this

screen shot 2017-09-27 at 1 24 04 pm

Note I used colored console which is not always supported depend on platform.

There will be another html report like this

screen shot 2017-09-27 at 1 29 32 pm

In the end user can click a button and download a zip which includes the report, data, csv and plot pictures.

There will be options in app to turn off the report, because we have to save every plot picture after every update, which could be a little bit burden if report was not needed.

@jmcalabrese @chfleming How do you feel about this design?

xhdong-umd commented 7 years ago

There are lots of tricky issues with file related operations.

Now the zip and download is working well, and the report is looking good. I need to further add the entries for every possible meaningful action, and test in windows(file related operations often have compatibility problems in various platform).

This is how the report look like. There is a floating table of content to help organize the report.

screen shot 2017-09-29 at 4 39 29 pm screen shot 2017-09-29 at 4 39 39 pm
xhdong-umd commented 7 years ago

And here is the control option for report:

screen shot 2017-09-29 at 4 50 23 pm
xhdong-umd commented 7 years ago

I have recorded every meaningful actions in every page, and tested in shinyapps.io server.

xhdong-umd commented 7 years ago

I'm working on preview report in hosted version. There are some more limitations of this method.

I can write some code to clean up the report on session end, but I still don't like the idea of sharing all users' file in app folder. The clean up code could also be skipped if there was some crash in app.

@jmcalabrese @chfleming Maybe it's better to just download the html file, then user can open it. So the button will be download report, and user will save it then open it.

It's also possible that I add some code try to detect the hosted mode

xhdong-umd commented 7 years ago

I finished the changes on work report and updated the hosted app:

screen shot 2017-10-11 at 12 45 10 pm screen shot 2017-10-11 at 12 46 37 pm
chfleming commented 7 years ago

That looks like a good solution.

I don't know what @jmcalabrese thinks, but I think it might be useful to also have a "canonical" report that has final data, final selected model, final outputs, without track of all choices made.

xhdong-umd commented 7 years ago

Yes all the intermediate steps may be a little bit overwhelming. Though it'll will be difficult to separate the steps needed for the final result and other steps. Some steps that changed data need to be included, like

For the data to be included in the download, what should we include, other than plot png/pdf?

chfleming commented 7 years ago

A canonical structure like that could also serve as a useful format for saving & loading sessions.

xhdong-umd commented 7 years ago

Previously I thought it's difficult to load session because a lot of data involved and we need to maintain consistence when some data is loaded.

Now I realize it's still possible but it need to be in a limited way, only the data, model fitting results, home ranges/occurrence can be restored. These should be the primary target of restore session because they are the time consuming steps.

xhdong-umd commented 7 years ago

To restore a session is still quite tricky. A lot of values are hold in reactive expressions, which will update automatically with input changes, and it's not supposed to be overwritten.

For example I can overwrite home range result anyway, but I also need to update some user input, like the models selected in the model summary table. There is no guarantee on the order of changes on model selected in table and the home range result. It's possible the model table updated later thus triggered the evaluation of reactive expression and calculate the home range again, which just defeat the purpose of saving home range result.

Shiny reactive doesn't provide detailed control of event orders, it's supposed to be automatic updates handled by Shiny. The best way I can think of now is to use a cache mechanism, so the calculation always check cached results before running a costly process. This way I can just update the cache after the session restored. This should be the best approach that don't disturb the reactive logic.

xhdong-umd commented 7 years ago

The cache mechanism worked in my test but didn't work in shiny app. For some reason the hash value of a function changed after parallel model fitting. I have reproduced the bug and reported to the author of digest.

Parallel code really is difficult when something is wrong...

xhdong-umd commented 7 years ago

It's difficult to fix the problem on digest (Shiny + parallel can be tricky). I found I can work around the issue by creating a wrapper function to move function object out of parameters.

xhdong-umd commented 7 years ago

With the work around I have made the cache mechanism work in app. If fit models/home range/occurrence was run with exactly same input again in one session, the later run will be finished instantly. So we can save session data include the cache data, and restore session will also restore cache, then these process can be finished quickly.

There are some tricky issues with data update though, since there are more source of truth for data -- previously it's just user input to determine the output, now the restoration of session can also update the data. This kind of multiple source of truth make the reactives in Shiny more complex and need more test to make sure everything works in every operation combination.

xhdong-umd commented 7 years ago
xhdong-umd commented 7 years ago

The current UI for report/session is as follows:

screen shot 2017-10-19 at 1 23 34 pm

It make senses to move the Load Session button to first page of import. Though that will make the local import box too busy, and the report box unbalanced.

Another option is to move both save session and load session to first page, which is not perfect either.

xhdong-umd commented 7 years ago

There is a bug with zip package I used (R utils::zip is not platform independent), which created an invalid zip when the folder to be compressed is empty. I have raised the issue with the package author. In the same time there is no real harm about this, just an error message in console when restoring this zip.

xhdong-umd commented 7 years ago

I have updated the repo and the web app. The work report and save/load session are finished for now.

I'll continue the work on the maps.

xhdong-umd commented 7 years ago

I may need to further test the session restoration. These file related operations often have problems in windows/Linux that need separate tests.

xhdong-umd commented 7 years ago

Turned out that R internal unzip ( the default method under windows) have problem unpacking zip created by zip::zip. The external tool unzip.exe have no problem with it.

xhdong-umd commented 7 years ago

Interestingly, I tested again in windows 10 VM, Linux VM, hosted mode, and there is no problem so far. The cached data can be loaded and used properly.

One thing to note is that the downloaded file can take some space. It's common to have about 10M zip session data.

I'll move to work on map now, and test with my home pc windows later.

xhdong-umd commented 7 years ago

I realized that to view report don't need two steps.

Previously I tried two steps because I want to open a link in hosted mode. That will need the report file generated before the link is ready. However a link in app cannot be session specific, that means we cannot separate different user's report files in a safe way.

So we have to download the report in hosted mode, but that doesn't need a explicit generate report step.

Now there will be just one button depend on app mode:

I also moved Load Session button to import page which is more logical, since the buttons in report box can be arranged in a balanced way now.

xhdong-umd commented 7 years ago

@jmcalabrese @chfleming I think the save/load session name can be changed to save/load cache, since the only data saved and restored are the input data and calculation caches. Restore session may give user an impression that more user interactions can be restored, but that is not practical.