> For the complete documentation index, see [llms.txt](https://docs.zep.us/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zep.us/zep-script/zep-script-guide/explore-zep-script/zep-script-example-code/sidebar-app.md).

# Sidebar App

A simple example that shows a sidebar app widget and closes it by clicking the X button.

To put an image in a widget, you need to **base64 encode the image** and wrap it in **an img tag** as shown in the example html code.

**1) File**

{% file src="/files/IrprvrbrAP4NhqowTcqk" %}

**2) main.js**

```jsx
// Function that works when the sidebar app is touched (clicked).
App.onSidebarTouched.Add(function (p) {
	p.tag.widget = p.showWidget("widget.html", "sidebar", 350, 350);
	p.tag.widget.onMessage.Add(function (player, data) {
		if (data.type == "close") {
			player.showCenterLabel("Widget has been closed.");
			player.tag.widget.destroy();
			player.tag.widget = null;
		}
	});
});

// Function is called when the player enters
App.onJoinPlayer.Add(function (p) {
	p.tag = {
		widget: null,
	};
});

// Function is called when the player exits 
App.onLeavePlayer.Add(function (p) {
	if (p.tag.widget) {
		p.tag.widget.destroy();
		p.tag.widget = null;
	}
});
```

**3) Image of the Sidebar App Running**

<div align="left"><figure><img src="/files/6NTKKgPZzvOVVu9p6GWe" alt=""><figcaption></figcaption></figure></div>

***
