Failing to install "htmlwidgets"

Hi, I am stuck with this issue of downloading the "htmlwidgets" package. Please help me figure it out. The output attached. Yes, I tried downloading "Rtools", but also failed.

> install.packages('htmlwidgets')
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/XXX/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependency ‘htmltools’


  There are binary versions available but the source versions are later:
            binary source needs_compilation
htmltools    0.5.2  0.5.4              TRUE
htmlwidgets  1.5.4  1.6.1             FALSE

  Binaries will be installed
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/htmltools_0.5.2.zip'
Content type 'application/zip' length 347438 bytes (339 KB)
downloaded 339 KB

package ‘htmltools’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
	C:\Users\XXX\AppData\Local\Temp\Rtmp0kND0g\downloaded_packages
installing the source package ‘htmlwidgets’

trying URL 'https://cran.rstudio.com/src/contrib/htmlwidgets_1.6.1.tar.gz'
Content type 'application/x-gzip' length 868433 bytes (848 KB)
downloaded 848 KB

* installing *source* package 'htmlwidgets' ...
** package 'htmlwidgets' successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
  namespace 'htmltools' 0.5.2 is being loaded, but >= 0.5.4 is required
Calls: <Anonymous> ... withCallingHandlers -> loadNamespace -> namespaceImport -> loadNamespace
Execution halted
ERROR: lazy loading failed for package 'htmlwidgets'
* removing 'C:/Users/XXX/Documents/R/win-library/4.0/htmlwidgets'
Warning in install.packages :
  installation of package ‘htmlwidgets’ had non-zero exit status

The downloaded source packages are in
	‘C:\Users\XXX\AppData\Local\Temp\Rtmp0kND0g\downloaded_packages’
> install.packages("Rtools")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/XXX/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
Warning in install.packages :
  package ‘Rtools’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

If you keep getting the same error message then maybe you haven installed the right RTools version for your R version (they have to match) or it has not been configured correctly.

For R 4.0.x you need to follow these instructions

https://cran.r-project.org/bin/windows/Rtools/rtools40.html

The problem is that since you are using an old R version the latest precompiled binary of htmltools available for it is too old and you don't have RTools properly installed to compile htmltools from source.