ipywidgets Label does not render any Latex formula.
I.e when I make labels in jupyterlab:
import ipywidgets as widgets
from IPython.display import display
from IPython.display import Math, Latex
a = widgets.Label(value=r"The $m$ in $\Huge E=mc^2$:")
b = widgets.Label(value = r'\(\color{red} {' + 'test' + '}\)')
display(a, b)
I get this:
The $m$ in $\Huge E=mc^2$:
\(\color{red} {test}\)
Was solved this by installing jupyterlab-matjax3. But this only worked till I restart Jupyterlab.
OS windows 10, Jupyter lab version 3.3.3
Related
I´m new in coding and for streamlit
I wanted to add aggrid
But when i try to run my code i get a JSON error that i have tried to fix
How can i fix my Attributeerror JSON?
I have uninstalled and reinstalled
pip uninstall streamlit-aggrid
pip install streamlit-aggrid
Nothing helps:
From the code for Aggrid:
import pandas as pd
import streamlit as st
import streamlit.components.v1 as components
from st_aggrid import GridOptionsBuilder, AgGrid, GridUpdateMode, DataReturnMode
and the lines for Aggrid configuration:
# Define AgGrid configuration
gb = GridOptionsBuilder.from_dataframe(df_selection)
gb.configure_default_column(groupable=True, value=True, enableRowGroup=True, aggFunc='sum', editable=True)
gridOptions = gb.build()
# Render AgGrid
components.html(AgGrid(df_selection, gridOptions=gridOptions, width='100%', height='500px', data_return_mode=DataReturnMode.JSON).get_html(),height=800)
I am trying to use a Python block in my R markdown document. Below is what I have been trying:
"""{r setup, include=FALSE}
require(reticulate)
use_python("/Users/hyunjindominiquecho/opt/anaconda3", required = T)
"""
"""{python}
# import the necessary python packages
import numpy as np
import pandas as pd
import scipy.stats as st
from rpy2 import robjects
import math
from scipy.optimize import newton
import torch
from pandas import dataframe
from statistics import mean
"""
but when I try to do this, R studio shows the following error:
Error in system2(command = python, args = paste0("\"", config_script, :
error in running command
How can I resolve this issue? Thank you,
What if you did:
```{python, engine.path = '/Users/hyunjindominiquecho/opt/anaconda3'}
import sys
print(sys.version)
```
What happens when you only run the first chunk? Do you still get the same error?
My problem is the import of a Google "Teachable machine" (https://teachablemachine.withgoogle.com/) to a Jupyter Notebook in Python.
For testing I made an easy teachable machine and exported it to this tensor code:
import tensorflow.keras
from PIL import Image
import numpy as np
# Disable scientific notation for clarity
np.set_printoptions(suppress=True)
# Load the model
model = tensorflow.keras.models.load_model('keras_model.h5')
# Create the array of the right shape to feed into the keras model
# The 'length' or number of images you can put into the array is
# determined by the first position in the shape tuple, in this case 1.
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
# Replace this with the path to your image
image = Image.open('Path to your image')
# Make sure to resize all images to 224, 224 otherwise they won't fit in the array
image = image.resize((224, 224))
image_array = np.asarray(image)
# Normalize the image
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
# Load the image into the array
data[0] = normalized_image_array
# run the inference
prediction = model.predict(data)
print(prediction)
Is there a possibility to run this code directly in a jupyter notebook with the same functionality?
Thanks a lot!
Yea it will but make sure about the dependencies are having the same version or not. as I got problems because I was having a lower version of TensorFlow and Keras.
this is the preferred version to run Google Teachable machine.
Keras==2.2.4
tensorflow==2.1.0
pillow==7.0.0
I try to import the following functions:
import numpy as np
def load_labels(path):
y = np.load(path)
return y
def print_sentence():
print("hi")
from a Jupyter notebook, with name "save_load" into another Jupyter notebook with the following code:
!pip install import-ipynb
import import_ipynb
import save_load
from save_load import load_labels, print_sentence
The function print_sentence works fine in the notebook, but with the function load_labels I receive the following error:
NameError: name 'np' is not defined
What could be the reason for this error? I've imported numpy as np in both notebooks.
In "save_load" instead of import numpy as np try import numpy, it worked for me.
You can try this:
import numpy as np
or
from numpy import *
I had the same problem when I was fixing my codes on VScode. Try saving the file. Then run it again.
I would like to run nbconvert with a preprocessor that removes cells marked with the tag "skip". I am able to do this from the command line, but when I try to use the nbconvert API within a notebook I run into problems.
An example
Following the example in the documentation, I get a notebook to work with.
from urllib.request import urlopen
url = 'http://jakevdp.github.com/downloads/notebooks/XKCD_plots.ipynb'
response = urlopen(url).read().decode()
import nbformat
nb = nbformat.reads(response, as_version=4)
I'll modify one cell so it gets skipped in the output.
nb.cells[1].metadata = {'tags': ['skip']}
Command line
Saving the file, and then running nbconvert from the command line:
nbformat.write(nb, 'nb.ipynb')
%%bash
jupyter nbconvert --to latex \
--TagRemovePreprocessor.remove_cell_tags='{"skip"}' \
--TagRemovePreprocessor.enabled=True \
'nb.ipynb'
This works. The output nb.tex file does not contain the cell tagged "skip".
API
Now let's try it using the API instead. First, without any preprocessing:
import nbconvert
latex, _ = LatexExporter().from_notebook_node(nb)
print(latex[:25])
\documentclass[11pt]{arti
Again, no problem. The conversion is working.
Now, trying to use the same preprocessor I used from the command line:
from traitlets.config import Config
c = Config()
c.RemovePreprocessor.remove_cell_tags = ('skip',)
c.LatexExporter.preprocessors = ['TagRemovePreprocessor']
LatexExporter(config=c).from_notebook_node(nb)
This time, I get:
ModuleNotFoundError: No module named 'TagRemovePreprocessor'
As far as I can see, this code matches the code sample in the documentation, except that I'm using the Latex exporter instead of HTML. So why isn't it working?
For your particular case, I believe you can resolve the issue by changing: c.RemovePreprocessor.remove_cell_tags = ('skip',) ->
c.TagRemovePreprocessor.remove_cell_tags = ('skip',)
For the benefit of others that come across this thread as I did by searching
ModuleNotFoundError: No module named 'TagRemovePreprocessor'
There is an open issue with TagRemovePreprocessor that causes all exporters other than the HTMLExporter (and LatexExporter?) to automatically disable this preprocessor.
In my case, I was attempting to use the NotebookExporter and needed to explicitly enable the preprocessor and change the preprocessing level like so:
import json
from traitlets.config import Config
from nbconvert import NotebookExporter
import nbformat
c = Config()
c.TagRemovePreprocessor.enabled=True # Add line to enable the preprocessor
c.TagRemovePreprocessor.remove_cell_tags = ["del_cell"]
c.preprocessors = ['TagRemovePreprocessor'] # Was previously: c.NotebookExporter.preprocessors
nb_body, resources = NotebookExporter(config=c).from_filename('notebook.ipynb')
nbformat.write(nbformat.from_dict(json.loads(nb_body)),'stripped_notebook.ipynb',4)