Skip to content

Update the Rserve interface. #1213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

drgrice1
Copy link
Member

@drgrice1 drgrice1 commented Mar 21, 2025

The primary change in this pull request is how the rserve_get_file method in the RserveClient.pl macro works. Previously it accepted a second optional local filename parameter. That parameter is no longer honored. If it is given it is ignored. I don't think that there are any problems in the OPL or Contrib that pass that argument, but even if they do it will still work. The filename just won't be the chosen one. The filename should not be a problem author choice. Furthermore, previously the method fell back to using the Rserve remote filename. That is also no longer used. Instead, the getUniqueName method is used that creates a filename that is dependent on the problem seed, psvn, problem UUID, etc. That means that the filename will not change each time that the problem is loaded. Unfortunately, the file is still downloaded every time the problem is loaded and overwrites the existing file (with the same contents), and that can't really be fixed without a major revision of the Rserve setup.

Note that all changes in this pull request are backwards compatible, and all existing problems will continue to function correctly. However, the courses html temporary directory will no longer be filled with files that are only used once before another copy of the file is created by another name the next time the problem is rendered (due to a preview, answer submission, etc.).

In addition there are two new methods added that are more convenient than the previous methods for generating R images or csv files. Those are the rserve_data_url and rserve_plot methods. These handle the details of creating these things in a much nicer way. See the added POD and examples in the POD for the usage and comparison to the old approaches.

The macro code and POD are also rather heavily clean up. The Rserve.pm module is also cleaned up. The _inherits method is removed from the Rserve.pm module, because contrary to the comments the inherits method of the $rserve object does work in the safe compartment, and so the _inherits method is not needed.

There is one other related change. The htmlLink method now has a new calling convention for adding additional attributes to the generated a tag. Previously these were added by passing a single string argument. For example, htmlLink($url, 'dataset', 'download="dataset.csv"'). That will still work, but passing the attributes in that way should be considered deprecated. Instead the attributes should be passed as additional attribute/value pairs after the url and link text. For example, htmlLink($url, 'dataset', download => 'dataset.csv'). Of course, this is useful for Rserve csv files to specify the filename that will be offered when the user clicks to download a csv file. Particularly since the default will now be something like ed721060-00b2-37fb-87c4-e3eb36c7ced2___5643740d-c34f-37c8-afc5-c2369fec26e1.csv. Previously it would have been something like file1231asdfasdf.csv. The new alias is worse, but that wasn't good either.

@dlglin
Copy link
Member

dlglin commented Mar 21, 2025

The instructions on the wiki (https://webwork.maa.org/wiki/R_in_WeBWorK#Transferring_files_from_the_R_server) will need to be updated to match.
Do we have sample problems for this?

@drgrice1
Copy link
Member Author

Note that the instructions on the wiki will still work as is. Although it would be good to add examples of using the new method. There are examples in the POD that are quite complete.

@drgrice1
Copy link
Member Author

I don't think there are any Rserve sample problems at this point.

@drgrice1 drgrice1 force-pushed the rserve-update branch 2 times, most recently from 4f237a4 to a62c8d7 Compare March 22, 2025 21:28
@drgrice1
Copy link
Member Author

I removed the chmod changes to LaTeXImage.pm and PGcore.pm from this pull request. I will add that in another pull request.

@drgrice1 drgrice1 force-pushed the rserve-update branch 2 times, most recently from 34bade4 to 4f0470c Compare March 24, 2025 10:34
Copy link
Contributor

@Alex-Jordan Alex-Jordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and it works as described.

@drgrice1
Copy link
Member Author

In case anyone is up for extensive testing of this, here are two set definition files. The first contains all OPL problems that use the RserveClient.pl macro, and the second contains all Contrib problems that use the macro. Note that there are other problems that load the macro, but don't use it that were not included in those set definitions.
RserveProblems.zip

@Alex-Jordan
Copy link
Contributor

When I tested, I just tested the two sample problems in the wiki. I looked closely at the file names (for the image and csv).

@drgrice1
Copy link
Member Author

Yeah, that is really enough. The problems in the OPL and Contrib don't do anything different really. But if you want to test extensively, then you can try the set definitions I just posted.

@drgrice1 drgrice1 force-pushed the rserve-update branch 4 times, most recently from b7f1491 to 0240cc0 Compare April 1, 2025 20:13
The primary change in this pull request is how the `rserve_get_file`
method in the `RserveClient.pl` macro works.  Previously it accepted a
second optional local filename parameter.  That parameter is no longer
honored.  If it is given it is ignored.  I don't think that there are
any problems in the OPL or Contrib that pass that argument, but even if
they do it will still work.  The filename just won't be the chosen one.
The filename should not be a problem author choice.  Furthermore,
previously the method fell back to using the Rserve remote filename.
That is also no longer used.  Instead, the `getUniqueName` method is
used that creates a filename that is dependent on the problem seed,
psvn, problem UUID, etc. That means that the filename will not change
each time that the problem is loaded. Unfortunately, the file is still
downloaded every time the problem is loaded and overwrites the existing
file (with the same contents), and that can't really be fixed without a
major revision of the Rserve setup.

Note that all changes in this pull request are backwards compatible, and
all existing problems will continue to function correctly. However, the
courses html temporary directory will no longer be filled with files
that are only used once before another copy of the file is created by
another name the next time the problem is rendered (due to a preview,
answer submission, etc.).

In addition there are two new methods added that are more convenient
than the previous methods for generating R images or csv files. Those
are the `rserve_data_url` and `rserve_plot` methods.  These handle the
details of creating these things in a much nicer way.  See the added POD
and examples in the POD for the usage and comparison to the old
approaches.

The macro code and POD are also rather heavily clean up.  The
`Rserve.pm` module is also cleaned up. The `_inherits` method is removed
from the `Rserve.pm` module, because contrary to the comments the
`inherits` method of the `$rserve` object does work in the safe
compartment, and so the `_inherits` method is not needed.

There are a couple of other related changes.

First, the `htmlLink` method now has a new calling convention for adding
additional attributes to the generated `a` tag. Previously these were
added by passing a single string argument. For example,
`htmlLink($url, 'dataset', 'download="dataset.csv"')`.  That will still
work, but passing the attributes in that way should be considered
deprecated.  Instead the attributes should be passed as additional
attribute/value pairs after the url and link text. For example,
`htmlLink($url, 'dataset', download => 'dataset.csv')`.  Of course, this
is useful for Rserve csv files to specify the filename that will be
offered when the user clicks to download a csv file.  Particularly since
the default will now be something like
`ed721060-00b2-37fb-87c4-e3eb36c7ced2___5643740d-c34f-37c8-afc5-c2369fec26e1.csv`.
Previously it would have been something like `file1231asdfasdf.csv`.
The new alias is worse, but that wasn't good either.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants