Supervisely
About SuperviselyEcosystemContact usSlack
  • 💻Supervisely Developer Portal
  • 🎉Getting Started
    • Installation
    • Basics of authentication
    • Intro to Python SDK
    • Environment variables
    • Supervisely annotation format
      • Project Structure
      • Project Meta: Classes, Tags, Settings
      • Objects
      • Tags
      • Image Annotation
      • Video Annotation
      • Point Clouds Annotation
      • Point Cloud Episode Annotation
      • Volumes Annotation
    • Python SDK tutorials
      • Images
        • Images
        • Image and object tags
        • Spatial labels on images
        • Keypoints (skeletons)
        • Multispectral images
        • Multiview images
        • Advanced: Optimized Import
        • Advanced: Export
      • Videos
        • Videos
        • Video and object tags
        • Spatial labels on videos
      • Point Clouds
        • Point Clouds (LiDAR)
        • Point Cloud Episodes and object tags
        • 3D point cloud object segmentation based on sensor fusion and 2D mask guidance
        • 3D segmentation masks projection on 2D photo context image
      • Volumes
        • Volumes (DICOM)
        • Spatial labels on volumes
      • Common
        • Iterate over a project
        • Iterate over a local project
        • Progress Bar tqdm
        • Cloning projects for development
    • Command Line Interface (CLI)
      • Enterprise CLI Tool
        • Instance administration
        • Workflow automation
      • Supervisely SDK CLI
    • Connect your computer
      • Linux
      • Windows WSL
      • Troubleshooting
  • 🔥App development
    • Basics
      • Create app from any py-script
      • Configuration file
        • config.json
        • Example 1. Headless
        • Example 2. App with GUI
        • v1 - Legacy
          • Example 1. v1 Modal Window
          • Example 2. v1 app with GUI
      • Add private app
      • Add public app
      • App Compatibility
    • Apps with GUI
      • Hello World!
      • App in the Image Labeling Tool
      • App in the Video Labeling Tool
      • In-browser app in the Labeling Tool
    • Custom import app
      • Overview
      • From template - simple
      • From scratch - simple
      • From scratch GUI - advanced
      • Finding directories with specific markers
    • Custom export app
      • Overview
      • From template - simple
      • From scratch - advanced
    • Neural Network integration
      • Overview
      • Serving App
        • Introduction
        • Instance segmentation
        • Object detection
        • Semantic segmentation
        • Pose estimation
        • Point tracking
        • Object tracking
        • Mask tracking
        • Image matting
        • How to customize model inference
        • Example: Custom model inference with probability maps
      • Serving App with GUI
        • Introduction
        • How to use default GUI template
        • Default GUI template customization
        • How to create custom user interface
      • Inference API
      • Training App
        • Overview
        • Tensorboard template
        • Object detection
      • High level scheme
      • Custom inference pipeline
      • Train and predict automation model pipeline
    • Advanced
      • Advanced debugging
      • How to make your own widget
      • Tutorial - App Engine v1
        • Chapter 1 Headless
          • Part 1 — Hello world! [From your Python script to Supervisely APP]
          • Part 2 — Errors handling [Catching all bugs]
          • Part 3 — Site Packages [Customize your app]
          • Part 4 — SDK Preview [Lemons counter app]
          • Part 5 — Integrate custom tracker into Videos Annotator tool [OpenCV Tracker]
        • Chapter 2 Modal Window
          • Part 1 — Modal window [What is it?]
          • Part 2 — States and Widgets [Customize modal window]
        • Chapter 3 UI
          • Part 1 — While True Script [It's all what you need]
          • Part 2 — UI Rendering [Simplest UI Application]
          • Part 3 — APP Handlers [Handle Events and Errors]
          • Part 4 — State and Data [Mutable Fields]
          • Part 5 — Styling your app [Customizing the UI]
        • Chapter 4 Additionals
          • Part 1 — Remote Developing with PyCharm [Docker SSH Server]
      • Custom Configuration
        • Fixing SSL Certificate Errors in Supervisely
        • Fixing 400 HTTP errors when using HTTP instead of HTTPS
      • Autostart
      • Coordinate System
      • MLOps Workflow integration
    • Widgets
      • Input
        • Input
        • InputNumber
        • InputTag
        • BindedInputNumber
        • DatePicker
        • DateTimePicker
        • ColorPicker
        • TimePicker
        • ClassesMapping
        • ClassesColorMapping
      • Controls
        • Button
        • Checkbox
        • RadioGroup
        • Switch
        • Slider
        • TrainValSplits
        • FileStorageUpload
        • Timeline
        • Pagination
      • Text Elements
        • Text
        • TextArea
        • Editor
        • Copy to Clipboard
        • Markdown
        • Tooltip
        • ElementTag
        • ElementTagsList
      • Media
        • Image
        • LabeledImage
        • GridGallery
        • Video
        • VideoPlayer
        • ImagePairSequence
        • Icons
        • ObjectClassView
        • ObjectClassesList
        • ImageSlider
        • Carousel
        • TagMetaView
        • TagMetasList
        • ImageAnnotationPreview
        • ClassesMappingPreview
        • ClassesListPreview
        • TagsListPreview
        • MembersListPreview
      • Selection
        • Select
        • SelectTeam
        • SelectWorkspace
        • SelectProject
        • SelectDataset
        • SelectItem
        • SelectTagMeta
        • SelectAppSession
        • SelectString
        • Transfer
        • DestinationProject
        • TeamFilesSelector
        • FileViewer
        • Dropdown
        • Cascader
        • ClassesListSelector
        • TagsListSelector
        • MembersListSelector
        • TreeSelect
        • SelectCudaDevice
      • Thumbnails
        • ProjectThumbnail
        • DatasetThumbnail
        • VideoThumbnail
        • FolderThumbnail
        • FileThumbnail
      • Status Elements
        • Progress
        • NotificationBox
        • DoneLabel
        • DialogMessage
        • TaskLogs
        • Badge
        • ModelInfo
        • Rate
        • CircleProgress
      • Layouts and Containers
        • Card
        • Container
        • Empty
        • Field
        • Flexbox
        • Grid
        • Menu
        • OneOf
        • Sidebar
        • Stepper
        • RadioTabs
        • Tabs
        • TabsDynamic
        • ReloadableArea
        • Collapse
        • Dialog
        • IFrame
      • Tables
        • Table
        • ClassicTable
        • RadioTable
        • ClassesTable
        • RandomSplitsTable
        • FastTable
      • Charts and Plots
        • LineChart
        • GridChart
        • HeatmapChart
        • ApexChart
        • ConfusionMatrix
        • LinePlot
        • GridPlot
        • ScatterChart
        • TreemapChart
        • PieChart
      • Compare Data
        • MatchDatasets
        • MatchTagMetas
        • MatchObjClasses
        • ClassBalance
        • CompareAnnotations
      • Widgets demos on github
  • 😎Advanced user guide
    • Objects binding
    • Automate with Python SDK & API
      • Start and stop app
      • User management
      • Labeling Jobs
  • 🖥️UI widgets
    • Element UI library
    • Supervisely UI widgets
    • Apexcharts - modern & interactive charts
    • Plotly graphing library
  • 📚API References
    • REST API Reference
    • Python SDK Reference
Powered by GitBook
On this page
  • Introduction
  • Function signature
  • Parameters
  • previews
  • examples
  • combined_data
  • height
  • selectable
  • preview_idx
  • preview_url
  • widget_id
  • Mini App Example
  • Init API client
  • Prepare data for ImageSlider widget
  • Initialize ImageSlider widget
  • Initialize Text, Editor and Button widgets, we will use
  • Create app layout
  • Create an app using the layout
  • Add functions to control widgets from python code

Was this helpful?

Edit on GitHub
  1. App development
  2. Widgets
  3. Media

ImageSlider

PreviousObjectClassesListNextCarousel

Last updated 1 year ago

Was this helpful?

Introduction

ImageSlider widget in Supervisely is a simple widget that displays images using Slider and is convenient to use when there is no need to add extra functions for displaying annotations or adjusting their settings, but only to display the images passed to it by a list of URLs or local paths.

Function signature

ImageSlider(
    previews=None,
    examples=None,
    combined_data=None,
    height=200,
    selectable=False,
    preview_idx=None,
    preview_url=None,
    widget_id=None,
)
default

Parameters

Parameters
Type
Description

previews

List[str]

List of previews URLs for the Slider widget

examples

List[List[str]]

List of image examples for the Slider widget

combined_data

List[dict]

List of image previews and examples URLs for the Slider widget

height

int

Height of the Slider widget

selectable

bool

Determines whether image selection is enabled or disabled

preview_idx

int

Index of the initially selected image in Slider

preview_url

str

URL of the initially selected image in Slider

widget_id

str

ID of the widget

previews

List of previews URLs for the Slider widget.

type: List[str]

default value: None

image_urls = [
    "https://www.w3schools.com/howto/img_nature.jpg",
    "https://www.quackit.com/pix/samples/18m.jpg",
    "https://i.imgur.com/35pUPD2.jpg",
    "https://i.imgur.com/fB2DBcM.jpeg",
    "https://i.imgur.com/OpSj3JE.jpg",
]

image_slider = ImageSlider(previews=image_urls)

examples

List of image examples for the Slider widget.

type: List[List[str]]

default value: None

image_urls = [
    "https://www.w3schools.com/howto/img_nature.jpg",
    "https://www.quackit.com/pix/samples/18m.jpg",
    "https://i.imgur.com/35pUPD2.jpg",
    "https://i.imgur.com/fB2DBcM.jpeg",
    "https://i.imgur.com/OpSj3JE.jpg",
]

example_urls = [
    [
        "https://www.w3schools.com/howto/img_nature.jpg",
        "https://www.quackit.com/pix/samples/18m.jpg",
        "https://i.imgur.com/35pUPD2.jpg",
        "https://i.imgur.com/fB2DBcM.jpeg",
        "https://i.imgur.com/OpSj3JE.jpg",
    ],
    ["https://www.quackit.com/pix/samples/18m.jpg"],
    ["https://i.imgur.com/35pUPD2.jpg"],
    ["https://i.imgur.com/fB2DBcM.jpeg"],
    ["https://i.imgur.com/OpSj3JE.jpg"],
]

image_slider = ImageSlider(previews=image_urls, examples=example_urls)

combined_data

List of image previews and examples URLs for the Slider widget.

type: List[dict]

default value: None

combined_data = [
    {
        "preview": "https://i.imgur.com/0XbKOJ3.jpeg",
        "moreExamples": ["https://i.imgur.com/0XbKOJ3.jpeg", "https://i.imgur.com/mIcObyL.jpeg"],
    },
    {
        "preview": "https://i.imgur.com/3rYHhEu.jpeg",
        "moreExamples": [
            "https://i.imgur.com/3rYHhEu.jpeg",
            "https://i.imgur.com/pSafUhg.jpeg",
            "https://i.imgur.com/yKc0xTb.jpeg",
        ],
    },
]

image_slider = ImageSlider(combined_data=combined_data)

height

Height of the Slider widget.

type: int

default value: 200

image_slider = ImageSlider(data=image_urls, height=100)

selectable

Determines whether image selection is enabled or disabled.

type: bool

default value: False

image_slider = ImageSlider(data=image_urls, selectable=True)

preview_idx

Index of the initially selected image in Slider. Use only if selectable is True.

type: int

default value: None

image_slider = ImageSlider(data=image_urls, selectable=True, preview_idx=4)

preview_url

URL of the initially selected image in Slider. Use only if selectable is True.

type: str

default value: None

image_slider = ImageSlider(
    data=image_urls, selectable=True, preview_url=image_urls[2]
)

widget_id

ID of the widget.

type: str

default value: None

Attributes and Methods
Description

get_selected_preview()

Get URL of the selected image in the slider.

set_selected_preview(value: str)

Sets URL of the image to be displayed as the preview image in the slider.

get_selected_idx()

Retrieves the index of the currently selected image in the slider.

set_selected_idx(value: int)

Sets the index of the image to be displayed as the preview image in the slider.

get_selected_examples()

Retrieves the list of URLs of the currently selected image examples in the slider.

is_selectable

Returns a boolean indicating whether image selection is enabled or disabled.

enable_selection()

Enables image selection.

disable_selection()

Disables image selection.

get_data_length()

Retrieves the length of the image URL list.

get_data()

Retrieves the list of image URLs and examples.

set_data(previews: List[str], examples: List[List[str]], combined_data: List[dict])

Sets the list of image URLs and examples.

append_data(previews: List[str], examples: List[List[str]], combined_data: List[dict])

Extends the list of image URLs and examples.

Mini App Example

You can find this example in our GitHub repository:

import os
import json

from dotenv import load_dotenv
import supervisely as sly
from supervisely.app.widgets import Button, Card, Container, Editor, Flexbox, Text, ImageSlider

Init API client

Init API for communicating with Supervisely Instance. First, we load environment variables with credentials:

if sly.is_development():
    load_dotenv("local.env")
    load_dotenv(os.path.expanduser("~/supervisely.env"))
api = sly.Api()

Prepare data for ImageSlider widget


image_urls = [
    "https://www.w3schools.com/howto/img_nature.jpg",
    "https://www.quackit.com/pix/samples/18m.jpg",
    "https://i.imgur.com/35pUPD2.jpg",
    "https://i.imgur.com/fB2DBcM.jpeg",
    "https://i.imgur.com/OpSj3JE.jpg",
]

example_urls = [
    [
        "https://www.w3schools.com/howto/img_nature.jpg",
        "https://www.quackit.com/pix/samples/18m.jpg",
        "https://i.imgur.com/35pUPD2.jpg",
        "https://i.imgur.com/fB2DBcM.jpeg",
        "https://i.imgur.com/OpSj3JE.jpg",
    ],
    ["https://www.quackit.com/pix/samples/18m.jpg"],
    ["https://i.imgur.com/35pUPD2.jpg"],
    ["https://i.imgur.com/fB2DBcM.jpeg"],
    ["https://i.imgur.com/OpSj3JE.jpg"],
]


combined_data = [
    {
        "preview": "https://i.imgur.com/0XbKOJ3.jpeg",
        "moreExamples": ["https://i.imgur.com/0XbKOJ3.jpeg", "https://i.imgur.com/mIcObyL.jpeg"],
    },
    {
        "preview": "https://i.imgur.com/3rYHhEu.jpeg",
        "moreExamples": [
            "https://i.imgur.com/3rYHhEu.jpeg",
            "https://i.imgur.com/pSafUhg.jpeg",
            "https://i.imgur.com/yKc0xTb.jpeg",
        ],
    },
]

Initialize ImageSlider widget

image_slider = ImageSlider(previews=image_urls, examples=example_urls)

Initialize Text, Editor and Button widgets, we will use

image_url = Text(status="info")
image_index = Text(status="info")
image_examples = Text(status="info")
data_length = Text(status="info")

text_container = Container(widgets=[image_url, image_index, image_examples, data_length])

button_url = Button(text="Get info")
button_set_url = Button(text="Select image by url")
button_set_index = Button(text="Select image by index")
button_extend_data = Button(text="Extend data")
button_set_data = Button(text="Set new data")
button_toggle_selectable = Button(text="Toggle selectable")
button_get_data = Button(text="Get data")

buttons_container = Flexbox(
    widgets=[
        button_url,
        button_set_url,
        button_set_index,
        button_extend_data,
        button_set_data,
        button_toggle_selectable,
        button_get_data,
    ]
)

all_data = Editor(height_lines=20)
all_data.hide()

Create app layout

Prepare a layout for the app using Card widget with the content parameter and place widgets that we've just created in the Container widget. Place order in the Container is important, we want buttons to be displayed above the Text widget.

card = Card(
    title="Image Slider",
    content=Container([image_slider, text_container, buttons_container, all_data]),
)

layout = Container(widgets=[card])

Create an app using the layout

Create an app object with the layout parameter.

app = sly.Application(layout=layout)

Our app layout is ready. It's time to handle button clicks.

Add functions to control widgets from python code

@button_url.click
def get_info():
    image_url.text = f"Image URL: {image_slider.get_selected_preview()}"
    image_index.text = f"Image index on slider: {image_slider.get_selected_idx()}"
    image_examples.text = f"Image examples: {image_slider.get_selected_examples()}"
    data_length.text = f"Data length: {image_slider.get_data_length()}"


@button_set_url.click
def set_url():
    image_slider.set_selected_preview("https://i.imgur.com/OpSj3JE.jpg")
    get_info()


@button_set_index.click
def set_index():
    image_slider.set_selected_idx(2)
    get_info()


@button_extend_data.click
def extend_data():
    image_slider.append_data(combined_data=combined_data[:1])
    get_info()


@button_set_data.click
def set_data():
    image_slider.set_data(combined_data=combined_data)
    get_info()


@button_toggle_selectable.click
def toggle_selectable():
    if image_slider.is_selectable:
        image_slider.disable_selection()
    else:
        image_slider.enable_selection()


@button_get_data.click
def get_data():
    data = image_slider.get_data()
    all_data.set_text(json.dumps(data, indent=4))
    all_data.show()
default
examples
data
height
selectable
preview_idx
preview_url

layout
🔥
supervisely-ecosystem/ui-widgets-demos/media/011_image_slider/src/main.py