Closed xhdong-umd closed 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.
And here is the control option for report:
I have recorded every meaningful actions in every page, and tested in shinyapps.io server.
csv
or .Rdata
if you feel any data should be included in the final zip.I'm working on preview report in hosted version. There are some more limitations of this method.
file://
protocol for security reasonsI 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
I finished the changes on work report and updated the hosted app:
on/off
switch is moved to first page, local data import box. Logically it apply to all case, not just local data import, but this is the best location we can have in first page. Putting it into a separate box will result a unbalanced layout.generate report
and download report
.
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.
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?
.rds
, since you can assign variable name in importing and avoid name conflictsresult$telemetry_list
, the current selected animal telemetry objects listresult$models
, the model fitting resultresult$selected_models
, the selected models subset, this is the rows selected in the model summary tableresult$home_range_list
, list of home ranges for selected modelsresult$occurrence_list
, list of occurrences for selected modelsA canonical structure like that could also serve as a useful format for saving & loading sessions.
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.
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.
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...
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.
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.
The current UI for report/session is as follows:
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.
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.
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.
I may need to further test the session restoration. These file related operations often have problems in windows/Linux that need separate tests.
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.
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.
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:
preview report
in local mode, which will open the report automatically like the first version.download report
in hosted mode, which will just download the report.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.
@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.
There will be console messages like this
Note I used colored console which is not always supported depend on platform.
.png
fileThere will be another html report like this
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?