sharing data across pages in quarto when loading from source file in R - rstudio

I have an index.qmd page in quarto that loads a dataset
```{r}
test <- TRUE
source(paste0(getwd(),"/loading.R"))
```
I have another page page1.qmd that needs to use the datasets loaded by the index page
```{r}
print(check)
print(test)
```
the loading.R file contains code to create check
check <- TRUE
Rendering using quarto render gives the following error:
←[1m←[34m[ 1/20] about.qmd←[39m←[22m
←[1m←[34m[ 2/20] page1.qmd←[39m←[22m
?[31m
processing file: page1.rmarkdown
|................................... | 50%
label: unnamed-chunk-1
?[31mQuitting from lines 2-7 (page1.rmarkdown)
?[39m?[31mError in print(check) : object 'check' not found
It seems that the source load doesn't put things into global memory. How can I go about doing this?

Related

PHPWord + dompdf "Unable to load PDF Rendering library" and "dompdf_config.inc.php" problems

I'm using PHPWord (https://github.com/PHPOffice/PHPWord) to generate a Microsoft Word file (.docx) which I save to my system. This works perfectly and as expected. I also want to save an Adobe Acrobat version of that file (.pdf) to my system. For that I'm relying on PHPWord in conjunction with dompdf (https://github.com/dompdf/dompdf). That's where the trouble begins.
My PHP code is the following:
// first, save the completed .docx file that I've generated
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, "Word2007");
$objWriter->save($path_docx);
// second, set PHPWord PDF rendering variables
\PhpOffice\PhpWord\Settings::setPdfRendererPath("/var/www/html/vendor/dompdf/dompdf");
\PhpOffice\PhpWord\Settings::setPdfRendererName("DomPDF");
// third, load the .docx file which we just saved above
$phpWord = \PhpOffice\PhpWord\IOFactory::load($path_docx);
// fourth, save the new PDF file to the location of choice
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, "PDF");
$xmlWriter->save("/var/www/html/export/my-pdf-version-of-the-file.pdf");
When I run the code above I get the following error:
Fatal error: Uncaught exception 'PhpOffice\PhpWord\Exception\Exception' with message 'Unable to load PDF Rendering library' in /var/www/html/vendor/phpoffice/phpword/src/PhpWord/Writer/PDF/AbstractRenderer.php:94 Stack trace: #0 /var/www/html/vendor/phpoffice/phpword/src/PhpWord/Writer/PDF.php(65): PhpOffice\PhpWord\Writer\PDF\AbstractRenderer->__construct(Object(PhpOffice\PhpWord\PhpWord)) #1 /var/www/html/vendor/phpoffice/phpword/src/PhpWord/IOFactory.php(44): PhpOffice\PhpWord\Writer\PDF->__construct(Object(PhpOffice\PhpWord\PhpWord)) #2 /var/www/html/assets/core/phpword.php(593): PhpOffice\PhpWord\IOFactory::createWriter(Object(PhpOffice\PhpWord\PhpWord), 'PDF') #3 /var/www/html/export/index.php(94): exportOutline(Array) #4 {main} thrown in /var/www/html/vendor/phpoffice/phpword/src/PhpWord/Writer/PDF/AbstractRenderer.php on line 94
I began searching Google for errors similar to this and came upon this Stack Overflow post: PHPWord to PDF not able to load library. They suggested editing some code within the "/var/www/html/vendor/phpoffice/phpword/src/PhpWord/Writer/PDF/AbstractRenderer.php" file. The code snippet referenced in that post is the following:
public function __construct(PhpWord $phpWord)
{
parent::__construct($phpWord);
$includeFile = Settings::getPdfRendererPath() . '/' . $this->includeFile;
if (file_exists($includeFile)) {
/** #noinspection PhpIncludeInspection Dynamic includes */
require_once $includeFile;
} else {
debug($includeFile);
// #codeCoverageIgnoreStart
// Can't find any test case. Uncomment when found.
throw new Exception('Unable to load PDF Rendering library');
// #codeCoverageIgnoreEnd
}
}
They suggested I get rid of this portion of the code which appears on the 4th line above:
. '/' . $this->includeFile
When I implemented that solution, however, it didn't fix my problem. Frustrated, I then looked at the value generated for $includeFile within that snippet of code. For me, the value was "/var/www/html/vendor/dompdf/dompdf/dompdf_config.inc.php". Once I saw that it was trying to include a file called "dompdf_config.inc.php" I then searched my directory for the file. It wasn't at the referenced location nor anywhere in my system!
At that point I began searching Google again for that file name and ended up on this Stack Overflow post: I Can't Find dompdf_config.inc.php or dompdf_config.custom.inc.php for setting "DOMPDF_UNICODE_ENABLED" true. That post suggests that dompdf 0.7.0 no longer relies on that configuration file. At this point I begin thinking that PHPWord's current version (which I'm using) which relies on dompdf has not been updated to support the current version of dompdf (which I'm using). I simply don't know.
My questions:
Can someone confirm if it's true that PHPWord's current version does not play well with dompdf's current version?
If the current version of both are supposed to work together, then what am I doing wrong and how do I fix it?
Thank you in advance for all of your help!
Note: I should note that I've included PHPWord and dompdf in my project via composer; so all relevant files are located in "/var/www/html/vendor" as one would expect. Also, I can't rely on TCPDF nor MPDF (which are alternate PDF rendering engines) because they generate files that don't meet the formatting needs I require for my project.

How to use SassDoc as parser for single file without generating full documentation files

Question relates to http://sassdoc.com package
I would like to parse each *.scss file in ./source folder, but instead of generating sassdoc folder i would like to create partial-html for each parsed file. For example:
parse: variables.scss and receive variables.html, without page header, sidebar - pure content, even without html and body tags.
My current code:
var gulp = require('gulp'),
sassdoc = require('sassdoc');
var paths = {
scss: [
'source/**/*.scss'
]
};
gulp.task('sassdoc', function () {
console.log("sassdoc task finished");
return gulp.src(paths.scss)
.pipe(sassdoc());
});
It's not possible with SassDoc' default theme. So you'd need to build your own theme to acheive this.
http://sassdoc.com/using-your-own-theme
Each item is given a file key in resulting data, so I would leverage that and do some merging.
That could potentially end up in a sassdoc-extra custom filter.
http://sassdoc.com/extra-tools
EDIT:
Actually your question is quite misleanding, you want a variable.html file but with no html ...
If all that you want is the raw JSON data from SassDoc, without any kind of theme processing, then the parse method is what you're looking for.
But again, unless you call SassDoc on each file separately, you'll get all files together, meaning post data processing to split them, that's why a custom theme (even with no html output) is the way to go.

Lektor: No Admin for flow fields

I can not figure out how to get the flow field working in admin,
I would like example shown at shown https://raw.githubusercontent.com/lektor/lektor-assets/master/screenshots/admin.png When I then click through to localhost:5000/admin/root/edit and get the http://i.imgur.com/EPCrBRC.png
Got I feel I am doing something simple wrong. But cutting it down to basic here is what I tried:-
$ cd /tmp/
$ lektor quickstart
Lektor Quickstart
=================
This wizard will generate a new basic project with some sensible defaults for
getting started quickly. We jsut need to go through a few questions so that
the project is set up correctly for you.
Step 1:
| A project needs a name. The name is primarily used for the admin UI and
| some other places to refer to your project to not get confused if multiple
| projects exist. You can change this at any later point.
> Project Name: flow-example
Step 2:
| This is the path where the project will be located. You can move a
| project around later if you do not like the path. If you provide a
| relative path it will be relative to the working directory.
> Project Path [/tmp/flow-example]:
Step 3:
| Do you want to generate a basic blog module? If you enable this the
| models for a very basic blog will be generated.
> Add Basic Blog [Y/n]: n
Step 4:
| Your name. This is used in a few places in the default template to refer
| to in the default copyright messages.
> Author Name [Brendan M. Sleight,,,]:
That's all. Create project? [Y/n] Y
$ cd flow-example/
$ echo "[fields.extra]
> label = Extra
> type = flow
> flow_blocks = text" >>./models/page.ini
$ cat ./models/page.ini
[model]
name = Page
label = {{ this.title }}
[fields.title]
label = Title
type = string
[fields.body]
label = Body
type = markdown
[fields.extra]
label = Extra
type = flow
flow_blocks = text
$ lektor server
* Project path: /tmp/flow-example/flow-example.lektorproject
* Output path: /home/bms/.cache/lektor/builds/76682e6a8f99116f0da91bcf96203e94
Started source info update
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Finished source info update in 0.05 sec
Started build
U index.html
U about/index.html
U projects/index.html
Finished build in 0.12 sec
Started prune
Finished prune in 0.00 sec
```
It takes a bit of careful documentation reading to find out what needs to go where to make flow blocks work.
You need to create a folder flowblocks at the same level where your content and models folders are.
Put your flowblock model files in this folder (example: image-paragraph.ini)
Create a blocks folder inside your templates folder.
Put your HTML templates for your flowblock in the blocks folder (example: image-paragraph.html)
Directory structure should look like this:
my-lektor-project
assets
content
flowblocks
image-paragraph.ini (your model)
models
templates
blocks
image-paragraph.html (your template for the block)
Currently the admin responds really badly to misconfiguration. Usually it just dies with an error you can see in the console window. Most likely the flow block itself does not exist or has a bug in it. Just open the console window and look at the error message printed. That might give an indication.
See https://www.getlektor.com/docs/models/flow/
To use Flow you need to define flow block models. If you are not familiar with Flow yet, you should read the Introduction Documentation to Flow first
Defining Models
Flow block models work pretty much exactly the same as Regular Models. The differences are mostly minor and of cosmetic nature. They are stored in the flowblocks/ folder and are ini files just like models.
Best explained with an example.
First, create a model containing a field with type set to flow and put it into models/flow_page.ini.
[model]
name = FlowPage
label = {{ this.title }}
[fields.title]
label = Title
type = string
[fields.body]
label = Body
type = flow
Create a new template in templates/flow_page.html. You can just copy page.html if you want.
Then write the following flow block config to flowblocks/colored_text.ini:
[block]
name = Text Block
button_label = Text
[fields.text]
label = Text
type = markdown
[fields.color]
label = Class
type = select
choices = red, blue, green
choice_labels = Red, Blue, Green
default = red
Now you need a template for the flow block. Add it to templates/blocks/colored_text.html.
<span style="color: {{ this.color }}">{{ this.text }}</span>
Finally, create a new subpage, choose FlowPage under model.
Now you can add the block we defined earlier to the body.

Parsing Liquid in a Jekyll generator before converting to JSON

Best to start by saying that I am very new to Ruby and Liquid. I have searched around looking for some resource on this issue, but as yet haven't been able to find anything of real use.
I have a Jekyll site, which utilises the HTML5 History API. I have a Jekyll generator plugin which creates a single JSON file which holds all the post and page content, ready for use with HTML5 PushState and PopState. This part is functioning properly and is tested.
My problem comes when I have a post/page on the site which has Liquid tags in it. I am guessing I need to parse these Liquid tags to get the template output before I create my JSON object for each post/page. Here is what I have for pages as an example:
# Iterate over all pages
site.pages.each do |page|
# Encode the page HTML content to JSON
link = page.url
#content = Liquid::Template.parse(page.content)
hash[link] = { "body_class" => page.data['body_class'], "content" => converter.convert(#content.render), "title" => '<h1>' + page.data["content_title"] + '</h1>' }
end
Now, this at the minute is basically removing all Liquid tags from the generated JSON file, leaving nothing in it's place.
Here is my full generator file on Github which is based very heavily on nice work by Jezen Thomas.
The output JSON file is also in that repo with the site, or can be accessed quickly here. The blog.html content is the last item in the JSON file and shows the empty h1 and div tags which should have content.

Joomla 3.0 and modules.php: static variable(2d) and caching - output error

I have the following problem:
I use Joomla 3.0.1 and my own developed Template(with bootstrap). When I turn the normal Joomla caching to on, my site has output errors. These errors are regarding to the modules.php from my template, because I use a static variable(array) to save all loaded module positions and the calulated or preseted spans for bootstrap in an 2 dimensional array. Like this:
top ->2,4,6
left ->3,3,3,3
right ->4,4,4
bottom ->1,2,3,4,2
header ->12
footer ->6,6
Without caching it works perfect, but when i turn it on, i have following errors:
Notice: Undefined index: logo in
/root/templates/jooag_workframe30/html/modules.php on line 82
Notice: Undefined index: mainmenu in
/root/templates/jooag_workframe30/html/modules.php on line 72
I know what this means and where to look, but i have no solution to fix this.
The modules.php code is here:
http://pastebin.com/s4tjXcKR
The entire template is here:
http://www.mediafire.com/?qrkbatdcbs4iq2v
If a position doesn't contain any modules (ie $modCount = 0) the $spanMatrix array won't have its key, so you should be checking whether it exists before trying to access it
I suggest you wrap lines 72-75 AND line 82 of your modules.php in the following statement:
if( isset( $spanMatrix[$modPosition] ))
{
.....
}
Let me know if it works

Resources