Change Widget that display posts from categories to tags

The main changes needed in order to use tags instead of categories would be:

In section one, change…

$args['category__in'] = $categories;

to

$args['tag__in'] = $categories;

And in the second section, change the cats loop:

$title = esc_attr($instance['title']);
$number_posts = (int) $instance['number_posts'];
$categories = (array) $instance['categories'];

echo '<p><label for="' . $this->get_field_id('title') . '">' . 'Title: ' . '</label><input id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" value="'. esc_textarea($title)  . '" /></p>';
echo '<p><label for="' . $this->get_field_id('number_posts') . '">' . 'Number of posts: ' . '</label><input id="' . $this->get_field_id('number_posts') . '" name="' . $this->get_field_name('number_posts') . '" value="'. esc_textarea($number_posts)  . '" /></p>';
$tags = get_tags('hide_empty=0');
?>
<p>
   <label>Tags to include: </label> <br />
   <?php foreach( $tags as $tag ) { ?>
      <label>
         <input type="checkbox" name="<?php echo $this->get_field_name('categories'); ?>[]" value="<?php echo $tag->term_id; ?>"  <?php if(in_array( $tag->term_id, $categories ) ) echo 'checked="checked" '; ?> /> 
         <?php echo $tag->name; ?>
      </label> <br />
   <?php } ?>
</p> 
<?php

Obviously, you can rename the variables and instance variables if wanted to reflect that you are now using tags instead of categories, but the changes I noted above will make it work properly.