LoginSignup
0
0

More than 1 year has passed since last update.

【R + Shiny Server + CentOS7】 Leafletがインストールできなくなった場合の対処方法

Last updated at Posted at 2022-05-13

前提となるシステム構成は
さくらのVPS
CentOS7
です。

2022年4月、間借りしていたサーバー上のLeafletを使ったアプリが突然不作動になりました。
R Studioのコンソールを見るとLeafletのインストールが再び必要ですとのこと。
そこでRStudioで下記のように試みてもインストールできません。

> install.packages("leaflet")
Installing package into ‘/home/****/R/x86_64-redhat-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
also installing the dependencies ‘terra’, ‘raster’

trying URL 'https://cran.rstudio.com/src/contrib/terra_1.5-21.tar.gz'
Content type 'application/x-gzip' length 636954 bytes (622 KB)
==================================================
downloaded 622 KB

trying URL 'https://cran.rstudio.com/src/contrib/raster_3.5-15.tar.gz'
Content type 'application/x-gzip' length 580594 bytes (566 KB)
==================================================
downloaded 566 KB

trying URL 'https://cran.rstudio.com/src/contrib/leaflet_2.1.1.tar.gz'
Content type 'application/x-gzip' length 2010129 bytes (1.9 MB)
==================================================
downloaded 1.9 MB

* installing *source* package ‘terra’ ...
** package ‘terra’ successfully unpacked and MD5 sums checked
** using staged installation
configure: CC: gcc -m64 -std=gnu99
configure: CXX: g++ -m64 -std=gnu++11
checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘terra’
* removing ‘/home/koji-ito/R/x86_64-redhat-linux-gnu-library/3.6/terra’
Warning in install.packages :
  installation of package ‘terra’ had non-zero exit status
ERROR: dependency ‘terra’ is not available for package ‘raster’
* removing ‘/home/koji-ito/R/x86_64-redhat-linux-gnu-library/3.6/raster’
Warning in install.packages :
  installation of package ‘raster’ had non-zero exit status
ERROR: dependency ‘raster’ is not available for package ‘leaflet’
* removing ‘/home/koji-ito/R/x86_64-redhat-linux-gnu-library/3.6/leaflet’
Warning in install.packages :
  installation of package ‘leaflet’ had non-zero exit status

installation of package ‘leaflet’ had non-zero exit statusというメッセージはLeafletをインストールできませんでしたという意味です。
メッセージを遡ると
configure: error: gdal-config not found or not executable.
どうやらgdalがネックになっているようです。

丁度新しいサーバーをお借りすることになっていたので、さくらのVPNにまっさらな状態から、R,RstudioServerをインストールして、Shiny Serverをインストールしてみました。
(OSの再インストールができない方が多いと思いますが、何かの参考になればと思いました)

真新しい状態のShiny Serverが出来上がったのですが、それに

> install.packages("leaflet")

を行っても全く同じでした。

これを解決した手順を以下に示します。
最初に概略を示します。

sqlite-devel
proj-6.0.0
gdal-3.2.0
をインストールして
Rstudioに戻ってleafletをインストールしてみます。
若干の修正をします.
Rstudioに戻ってleafletをインストールします。


では実際の手順を示しましょう。下記の実行には10分ほどかかります。

# yum install sqlite-devel
# wget https://download.osgeo.org/proj/proj-6.0.0.tar.gz
# tar xvzf proj-6.0.0.tar.gz
# cd proj-6.0.0
# ./configure
# make
# make install

ここまで行って、下記のようにprojのバージョンを確かめると6.0.0が入っています

# proj --version
Rel. 6.0.0, March 1st, 2019
<proj>: 
invalid option: --

適宜フォルダーを移動して、次はgdal3.2.0をインストールします。20~30分くらいかかるかもしれません。

# wget https://github.com/OSGeo/gdal/releases/download/v3.2.0/gdal-3.2.0.tar.gz
# tar xvzf gdal-3.2.0.tar.gz
# cd gdal-3.2.0
# ./configure
# make
# make install

ここまで行って、Rstudioに戻って
install.packages("leaflet")を行うと下記のエラーが出ました。

ERROR: dependency ‘raster’ is not available for package ‘leaflet’
* removing ‘/home/jfoito/R/x86_64-redhat-linux-gnu-library/3.6/leaflet’
Warning in install.packages :
  installation of package ‘leaflet’ had non-zero exit status

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

ここでもう一度
install.packages("leaflet")を行うと
下記のエラーになりました。
(再度上記コマンドを実行するのにどういう意味があったのかは不明ですが、とりあえずやってみました)

checking GDAL: linking with --libs only... yes
checking GDAL: /usr/local/share/gdal/pcs.csv readable... no
checking GDAL: checking whether PROJ is available for linking:... yes
checking GDAL: checking whether PROJ is available fur running:... ./gdal_proj: error while loading shared libraries: libgdal.so.28: cannot open shared object file: No such file or directory

gdal問題の再燃が明確になりましたが、これには下記のサイトを参考にします。
https://qiita.com/Chronona/items/bc7f508af1ff06d77b52

/etc/ld.so.conf.d/libgdal-x86_64.confにvimで下記の1行を書き込みます。

/usr/local/lib

もし上記ファイルがない場合は新規作成します。
新規作成の方法は

# cd /etc/ld.so.conf.d/
# vim libgdal-x86_64.conf

vimの使い方はネットを参考にして下さい。
image.png

ESCキーで抜けて
:wq
で保存します。

image.png

これを作成した後に下記を実行

# ldconfig

再びleafletをインストール
install.packages("leaflet")
しかし新たなエラーが

checking for geos-config... no
no
configure: error: geos-config not found or not executable.
ERROR: configuration failed for package ‘terra’

これには下記サイトを参考にして
https://stackoverflow.com/questions/53389181/installing-the-r-package-rgeos-on-linux-geos-config-not-found-or-not-executab

# yum install geos geos-devel

で対処しました。
再びRStudioに戻ってleafletを5分ほどかけてインストールしてようやく修復できました。

ここまでがうまくいった対処法です。
今のところ2回連続で成功しました!
2回目は# yum install geos geos-devel を # ldconfigのすぐ後に行ったのでスムースに運びました。


しかし、この結論に至るまで数多くの苦難がありました。
下記がその顛末ですが、何かの参考になれば幸いです。

Leafletがインストールできないために
https://community.rstudio.com/t/cannot-install-package-rgdal/20477
を参照してyumでインストールしました。

yum install gdal.x86_64 gdal-devel.x86_64 gdal-libs.x86_64 
yum install proj.x86_64 proj-devel.x86_64 
yum install proj-epsg.x86_64 proj-nad.x86_64

色々インストールして再びRStudioに戻ってleafletをインストールすると

> install.packages("leaflet")
Installing package into ‘/home/****/R/x86_64-redhat-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
also installing the dependencies ‘terra’, ‘raster’

trying URL 'https://cran.rstudio.com/src/contrib/terra_1.5-21.tar.gz'
Content type 'application/x-gzip' length 636954 bytes (622 KB)
==================================================
downloaded 622 KB

trying URL 'https://cran.rstudio.com/src/contrib/raster_3.5-15.tar.gz'
Content type 'application/x-gzip' length 580594 bytes (566 KB)
==================================================
downloaded 566 KB

trying URL 'https://cran.rstudio.com/src/contrib/leaflet_2.1.1.tar.gz'
Content type 'application/x-gzip' length 2010129 bytes (1.9 MB)
==================================================
downloaded 1.9 MB

* installing *source* package ‘terra’ ...
** package ‘terra’ successfully unpacked and MD5 sums checked
** using staged installation
configure: CC: gcc -m64 -std=gnu99
configure: CXX: g++ -m64 -std=gnu++11
checking for gdal-config... /usr/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 1.11.4
checking GDAL version >= 2.0.1... no
configure: error: terra is not compatible with GDAL versions below 2.0.1
ERROR: configuration failed for package ‘terra’
* removing ‘/home/koji-ito/R/x86_64-redhat-linux-gnu-library/3.6/terra’
Warning in install.packages :
  installation of package ‘terra’ had non-zero exit status
ERROR: dependency ‘terra’ is not available for package ‘raster’
* removing ‘/home/koji-ito/R/x86_64-redhat-linux-gnu-library/3.6/raster’
Warning in install.packages :
  installation of package ‘raster’ had non-zero exit status
ERROR: dependency ‘raster’ is not available for package ‘leaflet’
* removing ‘/home/koji-ito/R/x86_64-redhat-linux-gnu-library/3.6/leaflet’
Warning in install.packages :
  installation of package ‘leaflet’ had non-zero exit status

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

何やらGDALのバージョンが1.11.4であって、2.0.1より新しくないためエラーが出ているようです。

configure: GDAL: 1.11.4
checking GDAL version >= 2.0.1... no
configure: error: terra is not compatible with GDAL versions below 2.0.1

どうやらyumでは最近のバージョンをインストールできないようです。
確かめてみますとやはり・・・

[root@ik1-203-75403 /]# yum list installed | grep gdal
gdal.x86_64                         1.11.4-3.el7                        @epel   
gdal-devel.x86_64                   1.11.4-3.el7                        @epel   
gdal-libs.x86_64  

しかたがないため下記を参考にしてインストールします。
https://gist.github.com/satom9to5/7969812

ホームページを見るとGDALの最新バージョンは3.4.2ですが、あまり新しいと競合問題が発生する可能性があるため、2.4.2をインストールしました。
https://gdal.org/download.html

Terminalを使ってダウンロードします

wget https://download.osgeo.org/gdal/2.4.2/gdal-2.4.2.tar.gz

解凍します

# tar xvzf gdal-2.4.2.tar.gz

うまく行くように祈りつつインストールします(かなり時間がかかります)

# cd gdal-2.4.2
# ./configure
# make
# make install

再びRStudioに戻ってトライします

> install.packages("leaflet")

しかし、2.4.2をインストールしたのも関わらず、認識されていないようです。

configure: GDAL: 1.11.4
checking GDAL version >= 2.0.1... no
configure: error: terra is not compatible with GDAL versions below 2.0.1
ERROR: configuration failed for package ‘terra’
* removing ‘/home/koji-ito/R/x86_64-redhat-linux-gnu-library/3.6/terra’
Warning in install.packages :
  installation of package ‘terra’ had non-zero exit status
ERROR: dependency ‘terra’ is not available for package ‘raster’
* removing ‘/home/koji-ito/R/x86_64-redhat-linux-gnu-library/3.6/raster’
Warning in install.packages :
  installation of package ‘raster’ had non-zero exit status
ERROR: dependency ‘raster’ is not available for package ‘leaflet’
* removing ‘/home/koji-ito/R/x86_64-redhat-linux-gnu-library/3.6/leaflet’
Warning in install.packages :
  installation of package ‘leaflet’ had non-zero exit status

yumでインストールしたバージョンが残っていることに気づいてremoveします。

[root@ik1-203-75403 /] # yum remove gdal gdal-devel

この状態で再びleafletをインストールしても同じ症状です。
行き詰まりですが、下記の投稿が役に立ちました。
https://qiita.com/Chronona/items/bc7f508af1ff06d77b52

PROJは下記のところから
https://download.osgeo.org/proj/
6.1.1を入手することを試みます
https://download.osgeo.org/proj/proj-6.1.1.tar.gz
そして先ほどと同じように解凍、インストール作業を行います。

# wget https://download.osgeo.org/proj/proj-6.1.1.tar.gz
# tar xvzf /proj-6.1.1.tar.gz
# cd proj-6.1.1
# ./configure
# make
# make install

しかし./configureのところで下記エラーが

checking for SQLITE3... configure: error: Package requirements (sqlite3 >= 3.7) were not met:

No package 'sqlite3' found

SQLITE3が古いようです。
そこで下記を参照して最新版にしようとしましたがうまくいきません
https://qiita.com/kai_kou/items/c18b68a7916251231f6d

結局下記コマンドであっさりとアップデートできました

yum install sqlite-devel

バージョンをチェックすると 3.38.5です。
これでようやくproj-6.1.1がインストールができます。再びトライ。

# cd proj-6.1.1
# ./configure
# make
# make install

# proj --version
Rel. 6.1.1, July 1st, 2019
<proj>: 
invalid option: --
program abnormally terminated

ようやく6.1.1が入りました。
ここまでいろいろとやってきて次に何をすべきかわからなくなってきました。

そうかgdalのためにやっているのでした。
yumを使うと堂々巡りになりそうなのでぐっとこらえて、下記で再トライします。

# wget https://download.osgeo.org/gdal/2.4.2/gdal-2.4.2.tar.gz
# tar xvzf gdal-2.4.2.tar.gz
# cd gdal-2.4.2
# ./configure
# make
# make install

この途中(./configure)またPROJが古いというエラーが出たのですが、下記を参考にして
https://github.com/OSGeo/gdal/issues/1352
./configureの代わりに

./configure --with-proj=/usr/local

として

# make
# make install

しかしmakeの段階で

/gdal-3.4.3/.libs/libgdal.so: undefined reference to `sqlite3_column_origin_name'
/gdal-3.4.3/.libs/libgdal.so: undefined reference to `sqlite3_column_table_name'

のようなエラーメッセージが...ここで断念してOSを再インストールしてすべてクリアに。
最短の方法で行うべく、冒頭の書き込みに至ります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0