I have an .Rmd file where I would like to adapt the style depending on whether it is a mobile version or not - in css it is quite easy to check the window width with #media;
But then, let's say I have a root variable
--mobile: 1;
How would I be able to use this variable in an R chunk of a .Rmd file, i.e. how could I retrieve this variable?
I think this is essentially impossible, unless you are just parsing a .css file that you're intending to include:
CSS values can only be determined by looking at the .html file produced from the .Rmd file, but at the time the R code is running, the .html file hasn't yet been produced.
One way to get a guess at the value might be to have your R code render an .html file from the same .Rmd you're currently using (and you'll have to be careful that the nested .Rmd doesn't render itself again, in an infinite recursion). Then parse that .html file to find the active value of that variable within the code chunk that wants to know it.
Related
I am trying to modify a pbit archive in java in my application.
The point is to update the data source of a pbit without using any PowerBI application so I have to modify the DataModelSchema entry.
My problem is : when I read the file with an InputStream and display it in the console, there are blank spaces added between each letter so I am not able to search and replace the right string. Even if I add artificially blank spaces in my string.
For example if i search "content" or even "c o n t e n t", it never finds it.
That problem never appears when I read "normal" .zip archives.
An overview of my ouput when i read the file with additional blank spaces :
https://community.powerbi.com/t5/Service/modify-pbit-data-source-in-a-program/m-p/1744747#M124339
So I would like to get to know if there is a special encoding in pbit templates which might add special spaces or whatever if there is a way to read it properly.
Thanks for your help,
Regards
J.MARQUE
Just to clarify if someone get the same problem: that appears that it is not possible (for now) to update directly the content of the data schema of a pbit template, the only way seems to use Power BI REST API.
image.jpg
There is a load of lines like this with different pictures.
What i need to do is to make a script of some sort that would allow displaying those images without the need to write anything new in the body (it has to find the files from href's and display them ... without causing any more work for a person who puts those pictures there) and without the need to reorganize files (those files are tied to many other things ... change in the directory = everything crashes)
but i cant just find much ... most of the scripts i find requires me to place files in a specific folder or even worse ... to make img src tags for them
Can anyone point me towards some solution here ?
I'm not exactly clear on the question, but if I decipher it correctly a possible solution is to user scandir to read the contents of a directory. Likely will need to modify inside the foreach loop to fit your design (not sure if you have embedded script or not) but this will dynamically fetch and display images inside a directory.
if ($images = scandir('path_to_your_image_directory')) {
foreach ($images as $image) {
print '$image.jpg'; // Might need to preface the $image variable with path to your image directory
}
}
My problem is when I print the files within the directory, it prints out stuff like 'thumbs.db' and 'desktop.ini'. How to i make it print the name itself. All the files are .png by the way
static File overlayPath1 = new File(Minecraft.getMinecraft().mcDataDir, "\\TVMod\\" + filesList[0].getName());
thumbs.db and desktop.ini are both files in this directory, but normally in Windows they're hidden. However, because they're still there, they'll show up in your fileList.
If you don't want to use these files, you're going to have to skip them somehow. The implementation I'd suggest is to convert it to an ArrayList, then remove elements that don't match the .png extension.
However, without knowing more about your implementation, though, I can't easily suggest a way to do this.
Following on from my previous question, my program doesn't detect the 300 images that have just been created in a particular directory; instead, it only detects desktop.ini, which is not the case as I can physically see that the files have been created within said directory and do exist.
Can somebody please explain why this happens as when I run the program the next time, it seems to work just fine?
The only way that something is detected within the directory on the first run is when there is at least one file which exists in the directory before the program is compiled and executed.
Many thanks.
UPDATE: Files are detected as follows:
//Default greyscale image directory (to convert from greyscale to binary).
static File dirGrey = new File("test_images\\Greyscale");
//Array of greyscale image filenames.
static File imgListGrey[] = dirGrey.listFiles();
without knowing how you create the images, this question is akin to 'How many kittens are under my desk right now?'
Are you creating the files yourself? If so, are you closing any file handles referring to those files once they are created?
You're creating the file list in a static array, and it's created when the class containing the array is loaded by the Java class loader, which is probably before you create the image files. That's why the array contains an outdated list.
static is rarely needed, mostly useful for constants (things that never change, such as 42), for pure functions (Math.sqrt()) and a few other special cases. When you use it, you have to learn all the tricky initialization order stuff. Otherwise, just stick with non-static variables.
Using a Java servlet, is it possible to detect the true file type of a file, regardless of its extension?
Scenario: You only allow plain text file uploads (.txt and .csv) The user takes the file, mypicture.jpg, renames it to mypicture.txt and proceeds to upload the file. Your servlet expects only text files and blows up trying to read the jpg.
Obviously this is user error, but is there a way to detect that its not plain text and not proceed?
You can do this using the builtin URLConnection#guessContentTypeFromStream() API. It's however pretty limited in content types it can detect, you can then better use a 3rd party library like jMimeMagic.
See also:
Best way to determine file type in Java
When do browsers send application/octet-stream as Content-Type?
No. There is no way to know what type of file you are being uploaded. You must make all verifications on the server before taking any actions with the file.
I think you should consider why your program might blow up when give a JPEG (say) and make it defensive against this. For example a JPEG file is likely to have apparently very long lines (any LF of CR LF will be soemwhat randomly spread). But a so called text file could equally have long lines that might kill your program,
What exactly do you mean by "plain text file"? Would a file consisting of Chinese text be a plain text file? If you assume English text in ASCII or ANSI coding, you would have to read the full file as binary file, and check that e. g. all byte values are between, say, 32 and 127 plus 13, 10, 9, maybe.