extract all cell data from current Jupyter notebook - extract

Within Jupyter, there's two options to export notebooks to other formats, using nbconvert either on the command-line or as a library. Both require you to pass the original notebook as input (either as a file name or JSON data).
What I would like to do is essentially automatic, self-contained report generation, i.e. use the nbconvert library within a notebook, to export that same notebook to HTML/PDF on execution. I envisage the export code in the final cell of the document, with instructions to ignore that last cell on export.
My problem is in getting the data. Within the notebook I can access the code cells through In[1], Out[2] etc, but AFAIK there is no such functionality for markdown cells. There's also no (official) method to grab the name of the notebook (no __file__ attribute) to pass information that way.
There's plenty of examples to grab all the cell data from other notebooks - but is there a way to access all the cell data from the current notebook?

You can do this with the notebook filename and nbconvert, as you surmise. Doing some stuff client side might require extensions, one I can envision is a server extension to do the convert, and a bit of JS you write in the last code cell which renders a button, for example, and posts the notebook back to the convert server extension. Hiding certain cells (say, the Js cell) you can do in the convert extension, or with cell metadata and nbconvert templates. Given the flexibility of the architecture, there are quite a few ways to do this

Related

Plotly: Is it possible to dynamically change colors of traces on a .html file generated from a plotly figure using plotly's '.to_html()' function?

I've created an app that allows users to upload an excel or .csv file, extract the data and generate a plot for their desired data. I'm using plotly to produce the figures. I've included an option to create an .html file (so the user can access it later) containing the plot by using plotly's .to_html() function.
By default, this function creates plots with some level of interaction such as dynamic zoom, and capability to hide/unhide traces on the figure. This is great, but as I push this app out for others to use, I'd like them to also be able to change the colors of the traces on the figures, without requiring them to go into the source code. Ideally, the user would simply click on the plot/trace of interest on the legend (or some other button) then choose a new color.
Is it possible to add additional or custom interactive/dynamic functionality to the .html files generated by plotly? Specifically, is there a way to allow users to change the color of plots on a figure that has already been written to an .html file?
For context, I am using the python version of plotly.

How to import excel/csv with "File Import" widget in Foundry's Slate?

Context:
For a data pipeline we need to ingest excel spreadsheets directly into foundry (arriving via email). In order to avoid any manual handling error, we'd like to build a small slate app that basically just uploads an excel sheet and automatically appends it to an existing dataset (given schema, headers, etc.).
Unfortunately, there is very little documentation on the "File Import" widget or the API that gets called when drag and dropping a file into a folder.
Idea: Is there a way of uploading a file with slate? Could this file then be added to a dataset, similarly as with the prompt that opens when dropping it into a folder?
You actually don't have to build a Slate app to do this! Datasets that are made up of underlying .csv files support new additions of files directly.
Note: All of the following screenshots are from the dataset preview page.
For example, the following dataset I created from 4 .csv files:
And I can click on the Import button in the top right to add in more files (with the same schema, or not. Depends on if you want to strictly adhere to your applied schema.
If you have already applied a schema, you can also simply Import new files on top of the dataset, but the schemas of the files must exactly match those already present, otherwise your dataset will fail when attempted to be read.

R Writing Excel Document

My question is whether or not anybody knows of a better way to do what I'm already doing. I'm creating a report as a list, and trying to render it both in HTML and Excel.
I'm developing a shiny app that generates reports for Qualtrics surveys.
The results table is a list of HTML strings that I paste together and display in a shinydashboard. Here's a dput of the example results tables.
Here's how I'm creating the html results tables list -- the html_tabelize() function in my package. Here's a dput of the example input.
In the shiny server.R file the way I create the Excel file is with the following code:
output$downloadResults <- downloadHandler(
filename = 'tables.xls',
content = function(file) {
write(html_tabelize(main()[['blocks']]), file)
}
)
To summarize: I get the blocks, I run html_tabelize on them, and then I write the HTML output to a file called "tables.xls". When I open that file, because Excel can render HTML, it renders something like this:
My concern and problem with what I'm doing are two-fold:
If I were writing an Excel document instead of simply rendering HTML in Excel, then I could perhaps get a better formatted document. I'd like that.
When you download the results tables xls file and try to open it, you get a warning from Excel. I don't want the users of my app to see this warning, because it's distracting and could worry them about something that isn't really a concern.
I know that options exist for writing Excel files in R, but so far what I've seen indicates that their input must be either a data frame, or a list of data frames. The list I am rendering from has different types of components, like the question text, as well as data frames of results. Originally I was using pandoc, but pandoc, even when run from R, is a system binary, and it's difficult to list as a dependency (and if I can't list it as a dependency, it's tough to make sure it's installed for the users of my app). Additionally, I found out pandoc doesn't even convert to "real" Excel -- it also just saves HTML in a .xls file. Does anybody have any suggestions as to how I can improve this part of my app?

Creating a CSV file with the Report Generation Toolkit in Labview

I want to create .csv files with the Report Generation Toolkit in Labview.
They must actually be .csv files which can be opened with Notepad or something similar.
Creating a .csv is not that hard, it's just a matter of adding the extension to the file name that's going to be created.
If I create a .csv file this way it opens nicely in excel just the way it should, but if I open it in Notepad it shows all kind of characters and it doesn't even come close to the data I wrote to the file.
I create the files with the Labview code below:
Link to image (can't post image yet because I've got to few points)
I know .csv files can be created with the Write to Spreadsheet VI but I would like to use the Report Generation Toolkit because it's pretty easy to add columns and rows to the file and that is something I really need.
you can use the Robust CSV package on the lavag.org forum to read and write 2D arrays to CSV files.
http://lavag.org/files/file/239-robust-csv/
Calling a file "csv" does not make it a CSV file. I never used the toolkit to generate an Excel file, but I'm assuming it creates an XLS or XLSX file, regardless of what extension you give it, which is why you're seeing gibberish (probably XLS, since it's been around for a while and I believe XLSX is XML, not binary).
I'm not sure what your problem is with the write spreadsheet VI. It has an append input, so I assume you can use that to at least add rows directly to a file, although I can't say I ever tried it. I would prefer handling all the data in memory explicitly, where you can easily use the array functions to add rows or columns to the array and then overwrite the entire file.

SSIS Excel Destination with format

I try to export excel file with some format like:
Interior.Color
HorizontalAlignment
Font.Bold
and etc..
So the question is, can we do like that is SSIS..
and how to do it?
Not natively no.
If you always have the same output format you could create a formatted template spreadsheet, then make a copy of that to fill with data. I have seen this done before, the formulas and formatting were in the template, the SSIS job copied the template, then populated the copy.
SSIS is primarily a tool for moving data. Although it may be possible to write a script task or a custom component to do what you want, a better way would be to use a tool that is designed for presentation of data (a reporting tool, for example: SSRS) to do what you are trying to do.