Skip to content
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

Create HTML from C# in Jupyter #7126

Open
markbeij opened this issue Apr 11, 2024 · 0 comments
Open

Create HTML from C# in Jupyter #7126

markbeij opened this issue Apr 11, 2024 · 0 comments
Labels
untriaged New issue has not been triaged

Comments

@markbeij
Copy link

I hope someone here can help me with this.. I'm exploring the possibilities of data analysis using c# and see a lot of samples where you generate html from your Jupyter notebooks, like this blog from Microsoft: https://devblogs.microsoft.com/dotnet/an-introduction-to-dataframe/ by @pgovind

using Microsoft.AspNetCore.Html;
Formatter<DataFrame>.Register((df, writer) =>
{
    var headers = new List<IHtmlContent>();
    headers.Add(th(i("index")));
    headers.AddRange(df.Columns.Select(c => (IHtmlContent) th(c.Name)));
    var rows = new List<List<IHtmlContent>>();
    var take = 20;
    for (var i = 0; i < Math.Min(take, df.Rows.Count); i++)
    {
        var cells = new List<IHtmlContent>();
        cells.Add(td(i));
        foreach (var obj in df.Rows[i])
        {
            cells.Add(td(obj));
        }
        rows.Add(cells);
    }

    var t = table(
        thead(
            headers),
        tbody(
            rows.Select(
                r => tr(r))));

    writer.Write(t);
}, "text/html");

If I paste this in my notebook, I get
Error: (2,1): error CS0103: The name 'Formatter' does not exist in the current context

I also tried with a smaller example:

using Microsoft.AspNetCore.Html;
th(i("index"))

But I get
Error: (2,1): error CS0103: The name 'th' does not exist in the current context (2,4): error CS0103: The name 'i' does not exist in the current context

I'm using polyglot notebook in VS Code using C# Script.
Not sure what more info is helpfull.

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged New issue has not been triaged
Projects
None yet
Development

No branches or pull requests

1 participant