Jump to content

Replacing Image in Existing Organizer Topic


Recommended Posts

  • Seeq Team

Seeq Data Lab allows users to programatically interact with data connected to Seeq through Python. With this, users can create numerous advanced visualizations. Some examples of these are Sankey diagrams, Waterfall plots, radar plots and 3D contour plots. These plots can then be pushed back into Seeq Organizer for other users to consume the visualizations. 

A common workflow that can stem from this process is the need to update the Python visualizations in an existing Organizer Topic with new ones as newer data become available. Here we'll look over the steps of how you can update an existing Organizer Topic with a new graphic. 

Step 1: Retrieve the Workbook HTML

Behind every organizer topic is the HTML that controls what the reports display. We'll need to modify this HTML to add a new image will also retaining whatever pieces of Seeq content were already on the report.

pulled_workbooks = spy.workbooks.pull(spy.workbooks.search({'Name':'Organizer Topic Name'}))
org_topic = pulled_workbooks[0] # Note you may need to confirm that the first item in pulled_workbooks is the topic of interest
ws_to_update = org_topic.worksheets[0] # Choose the index based on the worksheet intended to be updated

ws_to_update.html # View the HTML behind the worksheet

Step 2: Create the HTML for The Image

The "add_image" function can be used to generate the HTML that will be inserted into the Organizer Topic HTML

replace_html = ws_to_update.document.add_image(filename = "Image_To_Insert.png")
replace_html

Step 3: Replace HTML and Push Back to Seeq

To find where in the Organizer Topic HTML to replace, we can use the re module. This will allow us to parse the HTML string to find our previously inserted image, which should begin with "<img src=". Note additional changes are required if multiple images are included in the report.

import re
before_html = re.findall("(.*)<img src=", ws_to_update.html)[0] # Capture everything before the image
after_html = re.findall(".*<img src=.*?>(.*)", ws_to_update.html)[0] # Captures everything after the image
full_html = before_html + replace_html + after_html # Combine the before and after with the html generated for the new picture
ws_to_update.html = full_html # Reassign the html to the worksheet and push it back to Seeq

spy.workbooks.push(pulled_workbooks)

 

  • Like 3
Link to comment
Share on other sites

  • 3 months later...

Hi, 

      Is there a way to add an html table to an organizer topic? I have a historic database, would like to upload this to seeq and allow seeq users to build onto the datatable. I am stuck pushing the data to the Organizer topic, I have converted my data to a panda dataframe and then to an HTML table.  Not sure if the page.document.add_image is the right way. 

 

Thanks for your help

Link to comment
Share on other sites

  • Seeq Team

Since its just HTML you can assign it to the worksheet's HTML directly. So you'd only need to follow Step 1 of pulling the workbook's HTML and a portion of Step 3 in the above example. Step 3 in your case would just be "ws_to_update.html = table_html" and then you'd push the workbook.

If you're looking to repeatedly update a table in Organizer with new information while retaining the other aspects of the Organizer then you'd need to find a way to capture that table using the re module. Tables in HTML have a table tag (i.e. <table> .... </table>) so you can create a regular expression to search based on this. For additional regular expression help, have a look at https://regex101.com/ to learn more and test different expressions. Once you have your regular expression finalized you can adapt Step 3 to account for that instead.

Link to comment
Share on other sites

  • 1 year later...

Hi Kristopher, thank you for detailing this topic.

I need some help on how to update a specific figure when I have more than one picture in the same topic organizer sheet. I tried to edit your previous search putting more information to it (something similar as below), but I am getting the IndexError: list out of range.

before_html = re.findall("(.*)<img src=\"/api/annotations/ADE7316A-36E9-46CF-A11C-71095994B787/images/Figure1", ws_to_update.html)[0]

Would you mind landing me a hand on that, please?

Link to comment
Share on other sites

  • Seeq Team

Hi Manoel,

In the case of multiple images you'll need to get more complex with how you capture sections of the HTML. Below are two routes I thought of but I'm sure there are others that may be better suited based on your particular scenario. Feel free to file a ticket at support.seeq.com for help. The options mentioned are based on a scenario where we're looking to update 2 images.

Option 1: Continue logic from previous comment and manually specify portions of HTML to capture before and after each image (good for a few number of replacements with standardized names)

# Similar code to previous comment
pulled_workbooks = spy.workbooks.pull(spy.workbooks.search({'Name':'Organizer Topic Name'}))
org_topic = pulled_workbooks[0] # Note you may need to confirm that the first item in pulled_workbooks is the topic of interest
ws_to_update = org_topic.worksheets[0] # Choose the index based on the worksheet intended to be updated
replace_html_1 = ws_to_update.report.add_image(filename = "ImageName1.png")
replace_html_2 = ws_to_update.report.add_image(filename = "ImageName2.png")

import re
image_name_1 = "ImageName1"
image_name_2 = "ImageName2"
before_html = re.findall(r"(.*)<img.*?src=.*{image_name_1}_v\d*.png.*?>".format(image_name_1 = image_name_1), ws_to_update.html)[0] # Capture everything before the 1st image
middle_html = re.findall(r"<img.*?src=.*{image_name_1}_v\d*.png.*?>(.*)<img.*?src=.*?{image_name_2}_v\d*.png.*?>".format(image_name_1 = image_name_1, image_name_2 = image_name_2), ws_to_update.html)[0] # Captures between the 1st and 2nd image
after_html = re.findall(r".*<img.*?src=.*?{image_name_2}_v\d*.png.*?>(.*)".format(image_name_2 = image_name_2), ws_to_update.html)[0] # Captures everything after the image
full_html = before_html + replace_html_1 + middle_html + replace_html_2 + after_html # Combine the before and after with the html generated for the new picture

ws_to_update.html = full_html # Reassign the html to the worksheet and push it back to Seeq
spy.workbooks.push(pulled_workbooks)

Option 2: Bulk find all images and capture the HTML for them. Insert new image HTML based on position/order (better for large number of replacements where image name can change)

# Same code as previous comment
pulled_workbooks = spy.workbooks.pull(spy.workbooks.search({'Name':'Organizer Topic Name'}))
org_topic = pulled_workbooks[0] # Note you may need to confirm that the first item in pulled_workbooks is the topic of interest
ws_to_update = org_topic.worksheets[0] # Choose the index based on the worksheet intended to be updated
replace_html_1 = ws_to_update.report.add_image(filename = "ImageName1.png")
replace_html_2 = ws_to_update.report.add_image(filename = "ImageName2.png")
  
import re
image_name_1 = "ImageName1"
image_name_2 = "ImageName2"
before_html_new = re.findall(r"(.*?)<img.*?src=.*?_v\d*.png.*?>", ws_to_update.html) # Capture everything before and in between each image
after_html_new = re.findall(r".*<img.*?src=.*?_v\d*.png.*?>(.*)", ws_to_update.html)[0] # Captures everything after the image
replace_html_list = [replace_html_1, replace_html_2]
full_html_list = []
for num, entry in enumerate(before_html_new): # Iterates through the non-image HTML and new image HTML, combining them based on their order in the list
    full_html_list.append(before_html_new[num])
    full_html_list.append(replace_html_list[num])
    if num == len(before_html_new)-1:
        full_html_list.append(after_html_new)
full_html = "".join(full_html_list)
ws_to_update.html = full_html # Reassign the html to the worksheet and push it back to Seeq
spy.workbooks.push(pulled_workbooks)

 

Edited by Kristopher Wiggins
Link to comment
Share on other sites

  • Seeq Team

One thing to add to this is SPy has been upgraded since this post was made to allow more options of templatizing content, including Organizers with images! Take a look at the documentation for Templates with images here, and the base documentation for Templates here.

 

This serves a different approach to replacing images in Organizer that doesn't require dealing directly with the HTML.

  • Thanks 1
Link to comment
Share on other sites

Hi @Kristopher Wiggins ,

I have used your second option and that worked well for me, thank you very much for that.

But I am also trying to apply @Emilio Conde's suggestion as I consider it a pretty much simple approach and also fits well my case. However I am facing an issue when it came to designate my images as mustache variables in my topic organizer worksheet. I am entering the “double curly-brace” syntax, but when I load it as a template and look at parameters, the mustache variables for the images are not being found. I could see that for the dynamics texts that I have included  in the same topic template are working fine (see below what is shown when a use print(document.code):

 

document.parameters = {
    "First App Impact": None,
    "First App": None
}
Link to comment
Share on other sites

  • Seeq Team

@Manoel Janio Borralho dos Santos my apologies, I forgot to mention that you need to upgrade your SPy to the latest version for this approach. Run 

spy.upgrade()

in a cell and then restart your Kernel and try again. The template will need to be recreated on the latest version of SPy, then see if this newly created template shows the images in the document.code.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...