Rのshiny をweb公開したときに日本語フォントが表示されないのがlibrary(showtext) で解決しなかった

ちょっとしたアプリケーションを作って、自分以外の、Rが使えない人でもデータを入力したら出力を得られるような仕様にしたい。
そこで、R のshiny を使ってweb にアクセスしたら使えるようにするわけだが、ローカル環境で構築したshiny アプリではプロット上の日本語フォントがきちんと表示されるのに、shinyapps.io にアップロードしてserver 環境下で使うと、日本語フォントが表示されない。
これはshiny server がlinux ベースで、日本語フォントを標準装備していないかららしいが、library(showtext) とすると日本語フォントが対応するらしい。
shinyapps.io - RjpWiki

しなかった。

下記を参考に、shiny server にR からコマンドを実行してフォントを読み込ませる。
リンクではsh ファイルをbash で実行しているが、system 関数でR側からコマンドを実行しているので、全部R側のスクリプトに納めておいた。
shinyapps.ioで任意の日本語フォントを使う - mana.bi

library(shiny)
#download.file("https://raw.githubusercontent.com/ltl-manabi/shinyapps.io_japanese_font/master/use_ipaex_font.sh", destfile = "use_ipaex_font.sh")

bashcode <- "
mkdir ~/tmp;
cd ~/tmp;
curl -O -L https://moji.or.jp/wp-content/ipafont/IPAexfont/IPAexfont00401.zip;
unzip IPAexfont00401.zip;
mkdir -p ~/.fonts/ipa;
cp ./IPAexfont00401/*.ttf ~/.fonts/ipa;
fc-cache -f ~/.fonts;
"
system(bashcode)

# Define UI for data upload app ----
ui <- fluidPage(
  # App title ----
  titlePanel("Uploading Files"),
  # Sidebar layout with input and output definitions ----
  sidebarLayout(
    # Sidebar panel for inputs ----
    sidebarPanel(
      # Input: Select a file ----
      fileInput("file1", "Choose CSV File",
                multiple = FALSE,
                accept = c("text/csv",
                         "text/comma-separated-values,text/plain",
                         ".csv")),
      # Horizontal line ----
      tags$hr(),
      # Input: Checkbox if file has header ----
      checkboxInput("header", "Header", TRUE),
      # Input: Select separator ----
      radioButtons("sep", "Separator",
                   choices = c(Comma = ",",
                               Semicolon = ";",
                               Tab = "\t"),
                   selected = ","),
      # Input: Select quotes ----
      radioButtons("quote", "Quote",
                   choices = c(None = "",
                               "Double Quote" = '"',
                               "Single Quote" = "'"),
                   selected = '"'),
      # Horizontal line ----
      tags$hr(),
      # Input: Select number of rows to display ----
      radioButtons("disp", "Display",
                   choices = c(Head = "head",
                               All = "all"),
                   selected = "head")
    ),
    # Main panel for displaying outputs ----
    mainPanel(
      # Output: Data file ----
      tableOutput("contents"),
      plotOutput("plot"),
    )
  )
)

# Define server logic to read selected file ----
server <- function(input, output) {
  hoge <- iris
  dat <- reactive({
    if(is.null(input$file1$datapath)){
      return(NULL)
    } else {
      req(input$file1)
      huga <- read.csv(input$file1$datapath)
      return(huga)
    }
  })
  output$contents <- renderTable({
    # input$file1 will be NULL initially. After the user selects
    # and uploads a file, head of that data file by default,
    # or all rows if selected, will be shown.
    req(input$file1)
    # when reading semicolon separated files,
    # having a comma separator causes `read.csv` to error
    tryCatch(
      {
        df <- read.csv(input$file1$datapath,
                 header = input$header,
                 sep = input$sep,
                 quote = input$quote)
      },
      error = function(e) {
        # return a safeError if a parsing error occurs
        stop(safeError(e))
      }
    )
    if(input$disp == "head") {
      return(head(df, input$is_holiday))
    }
    else {
      #return(input$is_holiday)
      return(df)
    }
  })
  output$plot <- renderPlot({
    plot(1, type="n")
    title("日本語")
    text(1, 1, "ほげほげ")
  })
}

# Create Shiny app ----
shinyApp(ui, server)