Failed to install leaflet package.

I tried to install leaflet package by following ways:

  1. install.packages("leaflet")
  2. by using the R studio package manager
    But i am failed. please help me.

share the error message.

install.packages("leaflet")
Installing package into ‘/home/satyam/R/x86_64-pc-linux-gnu-library/3.4’
(as ‘lib’ is unspecified)
Warning in install.packages :
dependency ‘raster’ is not available
also installing the dependency ‘png’

trying URL 'https://cloud.r-project.org/src/contrib/png_0.1-7.tar.gz'
Content type 'application/x-gzip' length 24990 bytes (24 KB)

downloaded 24 KB

trying URL 'https://cloud.r-project.org/src/contrib/leaflet_2.0.3.tar.gz'
Content type 'application/x-gzip' length 2039454 bytes (1.9 MB)

downloaded 1.9 MB

  • installing source package ‘png’ ...
    ** package ‘png’ successfully unpacked and MD5 sums checked
    ** libs
    gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG libpng-config --cflags -fpic -g -O2 -fdebug-prefix-map=/build/r-base-AitvI6/r-base-3.4.4=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c read.c -o read.o
    /bin/bash: libpng-config: command not found
    read.c:3:10: fatal error: png.h: No such file or directory
    #include <png.h>
    ^~~~~~~
    compilation terminated.
    /usr/lib/R/etc/Makeconf:159: recipe for target 'read.o' failed
    make: *** [read.o] Error 1
    ERROR: compilation failed for package ‘png’
  • removing ‘/home/satyam/R/x86_64-pc-linux-gnu-library/3.4/png’
    Warning in install.packages :
    installation of package ‘png’ had non-zero exit status
    ERROR: dependencies ‘png’, ‘raster’ are not available for package ‘leaflet’
  • removing ‘/home/satyam/R/x86_64-pc-linux-gnu-library/3.4/leaflet’
    Warning in install.packages :
    installation of package ‘leaflet’ had non-zero exit status

The downloaded source packages are in
‘/tmp/RtmpR0rRob/downloaded_packages’

I'm not sure on this one, but the error message mentions it can't find "lib" (where it would install the package) and then can't find another package that the one you are installing relies upon. My starting point would be checking whether the lib / package directory is set correctly. Sorry I'm not sure what exactly it would be though.

It seems you are missing a system dependency (libpng), you haven't tell us on which operating system are you so I can't give you any specific advice but you can Google how to install it in your system

My operation system is ubuntu 18. i installed libpng dependency but still facing same issue.

Have you also installed libpng-dev? the file png.h seems to come from there.