R shinydashboardplus flipbox - how to remove images - r

I'd like to have no images for the flipbox, how can I do it? Tried this (and also setting to NULL):
flipBox(
id = 1,
main_img = "",
header_img = "",
...
but instead it gives me this strange image.

I had the same problem and checked the source code of the function. If you copy it into a R script file there is the following code in line 13/14:
shiny::tags$img(class = "avatar",
src = main_img,
alt = "Avatar")
Since you cannot control this behavior by a flipBox() argument, I defined my own function flippBox and deleted the alt = "Avatar" argument. I do not see the necessity for this strange pill anyways..

Related

shQuote() breaks system() command rather than escaping spaces

I'm running the GCMS software AMDIS inside an R script to analyze GCMS data. The basic syntax is:
system("AMDIS_PATH GCMS_FILE_PATH /S /GC /GE /E"
With "/S /GC /GE /E" referring to functionalities within the AMDIS program.
I want to make the code 'fool-proof', so I'm allowing paths with "/" instead of "\\". And I'm also allowing spaces in the paths, escaping them with shQuote(..., type = "cmd")
Which means the full code looks like
system(paste(shQuote(gsub("/", "\\", AMDIS_PATH, fixed = T), type = 'cmd'), shQuote(gsub("/", "\\", GCMS_FILE_PATH, fixed = T), type = 'cmd'), "/S /GD /GS /E"))
This code does not work (output = 65535), but there's a catch:
If I remove the shQuotes from my GCMS_FILE_PATH. Then everything works like it should (so long as the FILE_PATH does not contain any spaces).
So executing the code like this does work:
system(paste(shQuote(gsub("/", "\\", AMDIS_PATH, fixed = T), type = 'cmd'), gsub("/", "\\", GCMS_FILE_PATH, fixed = T), "/S /GD /GS /E"))
Any idea why shQuote works fine for the AMDIS_PATH, but not for the GCMS_FILE_PATH? And how I can run my code and still escape spaces in the GCMS_FILE_PATH?

R/exams d2l multiple choice question doesn't select correct answer

I use the following to create a D2L exam from the "capital.Rmd" example (I converted the question to schoice)
exams2blackboard("capitals.Rmd", n =3, name = "testquiz" )
After I upload the testquiz.zip file, I notice that the correct answer must be manually chosen on the D2L platform.
I was wondering if there is a workaround.
Many Thanks,
Umut
If you want the correct solution to be selected, do not use the Import option from the Question Library or from the Quiz itself. Use the Import/Export/Copy Components under the Course Admin tab.
If you import the questions through the following steps, BrightSpace correctly picks the right solution. It’s a bit longer but seems to correctly choose the solution.
Under the Course Admin tab of your course, go to
'Import/Export/Copy Components' -> ‘Import Components’ -> Start -> (drag and drop the ZIP file)
Click ‘Advanced Options…’
This step will take a few minutes for large files; if you do not click
Advanced Options, then the import will automatically import the
questions into the 'Question Library' and will generate a Quiz with the
imported questions; you do not want this.
-> Continue -> Continue -> at this point choose 'Question Library' from the section 'Select Components to Import'
I would not choose ‘Quizzes’ because it automatically creates a quiz
and makes it available to students. It has the unfortunate side-effect
of making ALL the questions available, which means all the versions of
various dynamic questions; this is not something we want.
-> Continue -> Continue. This stage takes a few minutes for large
imports.
Now the Questions are available in the Question Library and can be used to generate new quizzes. Each question has the correct answer selected already. This works for ‘schoice’ and ‘mchoice’ versions of questions. Currently, plots are not imported, though, still trying to figure out why.
This problem is new to me. In earlier versions of Brightspace/D2L the import of single-choice and multiple-choice exercises via exams2blackboard() worked well. Possibly, D2L changed in the meantime given that neither the current release version from CRAN nor the development version from R-Forge work for you.
D2L also supports other import formats and we did play around with some of these. See the following discussions in the R/exams forum on R-Forge:
https://R-Forge.R-project.org/forum/forum.php?thread_id=33404&forum_id=4377&group_id=1337
https://R-Forge.R-project.org/forum/forum.php?thread_id=33657&forum_id=4377&group_id=1337
Notably we tried to use the XML-based QTI 2.1 format that seems to be employed by D2L internally. However, D2L apparently uses a particular custom flavor of QTI 2.1. It should be possible to reverse engineer that and improve exams2qti21() correspondingly but so far (to the best of my knowledge) no one put the time and effort into this that would be needed.
For simple single/multiple choice questions a CSV-based exchange format can also be used. I have put together a very basic exams2d2l() function that was posted in the threads above and that I'm also including below. It can set up the CSV file for a single exercise like the capitals.Rmd exercise that you use above. For plain text exercises like that it seems to work well but not for more complex elements (graphics, code, math, etc.).
exams2d2l <- function(file, dir = ".", ## n = 1L, nsamp = NULL disabled for now
name = NULL, quiet = TRUE, edir = NULL, tdir = NULL, sdir = NULL, verbose = FALSE,
resolution = 100, width = 4, height = 4, svg = FALSE,
encoding = "", converter = NULL, ...)
{
## for Rnw exercises use "ttm" converter otherwise "pandoc" converter
if(any(tolower(tools::file_ext(unlist(file))) == "rmd")) {
if(is.null(converter)) converter <- "pandoc"
} else {
if(is.null(converter)) converter <- "ttm"
}
## output directory or display on the fly
## output name processing
if(is.null(name)) name <- tools::file_path_sans_ext(basename(file))
## set up .html transformer and writer function
htmltransform <- make_exercise_transform_html(converter = converter, ...)
## create exam with HTML text
rval <- xexams(file,
driver = list(sweave = list(quiet = quiet, pdf = FALSE, png = !svg, svg = svg,
resolution = resolution, width = width, height = height, encoding = encoding),
read = NULL, transform = htmltransform, write = NULL),
dir = dir, edir = edir, tdir = tdir, sdir = sdir, verbose = verbose)
## currently: only a single exercise
rval <- rval[[1L]][[1L]]
## put together CSV
cleanup <- function(x) gsub('"', '""', paste(x, collapse = "\n"), fixed = TRUE)
rval <- c(
'NewQuestion,MC,,,',
sprintf('ID,"%s",,,', cleanup(rval$metainfo$file)),
sprintf('Title,"%s",,,', cleanup(rval$metainfo$name)),
sprintf('QuestionText,"%s",,,', cleanup(rval$question)),
sprintf('Points,%s,,,', if(is.null(rval$metainfo$points)) 1 else rval$metainfo$points),
'Difficulty,1,,,',
'Image,,,,',
paste0('Option,', ifelse(rval$metainfo$solution, 100, 0), ',"', cleanup(rval$questionlist), '",,"', cleanup(rval$solutionlist), '"'),
'Hint,,,,',
sprintf('Feedback,"%s",,,', cleanup(rval$solution))
)
writeLines(rval, file.path(dir, paste0(name, ".csv")))
invisible(rval)
}

How to copy and paste indd file content into an another indd file?

I'm newbie in indesign scripting stuffs.So I apologise as I couldn't post my trials.
Objective:
I have an indd document which will have figure caption,label etc. I need to copy content(figure which is editable) from other indd file to this document where related figure label exists.
For example:
sample.indd
Some text
Fig.1.1 caption
some text
I need to copy the content of figure1.indd and paste into the sample.indd document where Fig.1.1 string exists and so on. Now I'm doing it manually. But am supposed to automate this.
So, I need some hint how to acheive it using extendscript?
I have found something like below to do this, but I don't have any clue to develop it further and also am not sure whether this approach is correct to get my result. Pls help me
myDocument=app.open(File("file.indd"),false); //opening a file to get the content without showing.
myDocument.pages.item(0).textFrames.item(0).contents="some text";
//here I could set the content but I don't knw how to get the content
// ?????? Then I have to paste the content into active document.
I found the script for my requirement.
var myDoc = File("sample.indd");//Destination File
var myFigDoc = File("fig.indd");//Figure File
app.open(File(myFigDoc));
app.activeDocument.pageItems.everyItem().select();
app.copy();
app.open(File(myDoc));
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "FIG. 1.1 ";//Figure caption text
//app.findGrepPreferences.appliedParagraphStyle = "FigureCaption";//Figure Caption Style
myFinds = app.activeDocument.findGrep();
for(var i=0;i<myFinds.length;i++){
myFinds[i].insertionPoints[0].contents="\r";
myFinds[i].insertionPoints[0].select();
app.paste();
}
app.findGrepPreferences = app.changeGrepPreferences = null;
If acceptable for you, you can place an indesign file as link (place…). So a script could try to catch the "fig…" strings and do the importation.
Have a look at scripts that use finGrep() and place() command.

`ControlCommand` not working with `ComboLBox`

Instead of returning the currect selected font, it returns 0.
ShellExecute("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("!O")
Send("F")
WinWaitActive("Font")
$select = ControlCommand("Font", "", "[CLASS:ComboLBox; INSTANCE:1]", "GetCurrentSelection", "")
MsgBox(0,"", $select)
That control is actually a "Combo L Box", not a ComboBox. As the AutoIt helpfile says under ControlCommand:
Certain commands that work on normal Combo and ListBoxes do not work
on "ComboLBox" controls.
The ComboLBox is actually a child control of the ComboBox, and is just the drop down part of it. If you use a more advanced window finder like Spy++, you will actually see there is a ComboBox there, with two children (an Edit and the ComboLBox). So your code will work if you change "[CLASS:ComboLBox; INSTANCE:1]" to "[CLASS:ComboBox; INSTANCE:1]".
Furthermore, you can improve your code for triggering the menu item, so that the entire operation can be done in the background.
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Local $IDM_FONT = 33
Local $hWindow = WinGetHandle("Untitled - Notepad")
_WinAPI_PostMessage($hWindow, $WM_COMMAND, $IDM_FONT, 0)
Local $hFontWin = WinWait("Font")
$select = ControlCommand($hFontWin, "", "ComboBox1", "GetCurrentSelection", "")
WinClose($hFontWin)
MsgBox(0,"", $select)
Alternatively, you can interact with the ComboLBox in the same way you would a listbox:
$hLBox = ControlGetHandle($hFontWin, "", "ComboLBox1")
$itemIndex = _GUICtrlListBox_GetCurSel()
$select = _GUICtrlListBox_GetText($hLBox, $itemIndex)
Why ControlCommand doesn't work with this particular type of list box I have no idea. I can only guess that internally they check the control class against "ComboBox" and "ListBox" and return zero if there is no match.
You can use ControlGetText() to read the name of the currently active font, if this is what you want to accomplish.
ShellExecute("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("!O")
Send("F")
WinWaitActive("Font")
$select = ControlGetText("Font", "", "Edit1")
MsgBox(0,"", $select)

R code mcmcplots function

Is there a way to make the R mcmcplot() function not open a browser when it's called? I need to run my R code on a cluster and if mcmcplot() tries to open a browser, it will puke.
Can the output be dumped to a file maybe?
That function writes everything to a file and also opens it in a browser. If you dont want to open the browser I would recommend editing the function to pass whether or not you want to open in a browser as an argument. You can retreive the function by just typing its name without any parenthesis.
mcmcplot
then copy that output to a editor and at the beginning change the name of the function and add teh argument:
mcmcplotnew=function (mcmcout, parms = NULL, regex = NULL, random = NULL,
leaf.marker = "[\\[_]", dir = tempdir(), filename = "MCMCoutput",
extension = "html", title = NULL, heading = title, col = NULL,
lty = 1, xlim = NULL, ylim = NULL, style = c("gray", "plain"),
greek = FALSE,ShouldIPlotinbrowser=T) #new argument here
then there are much more parts of the function
then at the end there is
cat("\r", rep(" ", getOption("width")), "\r", sep = "")
cat("\n</div>\n</div>\n", file = htmlfile, append = TRUE)
.html.end(htmlfile)
full.name.path <- paste("file://", htmlfile, sep = "")
browseURL(full.name.path)
invisible(full.name.path)
}
Where you have the browsURL line, make it something like:
if(ShouldIPlotinbrowser) { browseURL(full.name.path) }
Then initialize that function before you run it with:
mcmcplotnew(whatever, usual, arguments,then,ShouldIPlotinbrowser=F)
Looking at the source, it seems not. There is an unconditional call to browseURL() there. Maybe by making a dummy version of that function which does nothing in your global namespace, it's effect can be avoided.
browseURL <- identity
This may break other browser activity as well, so after the mcmcplot calls, you may want to
rm(browseURL)
Alternatively, copy all the code from mcmcplot except for the browseURL line and use that function instead.

Resources