開始使用免費開始

上傳文字檔(ui)

如果文字非常長,與其在文字框內輸入一大段內容,直接上傳文字檔會更方便。

在 Shiny 應用程式中,上傳檔案可以使用 fileInput()

本練習屬於課程

案例研究:使用 R 的 Shiny 建置網頁應用程式

檢視課程

練習說明

在 Shiny 應用程式中加入一個檔案輸入元件,inputId 為「file」,label 為「Select a file」。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

ui <- fluidPage(
  h1("Word Cloud"),
  sidebarLayout(
    sidebarPanel(
      textAreaInput("text", "Enter text", rows = 7),
      # Add a file input
      ___,
      numericInput("num", "Maximum number of words",
                   value = 100, min = 5),
      colourInput("col", "Background color", value = "white")
    ),
    mainPanel(
      wordcloud2Output("cloud")
    )
  )
)

server <- function(input, output) {
  output$cloud <- renderWordcloud2({
    create_wordcloud(input$text, num_words = input$num,
                     background = input$col)
  })
}

shinyApp(ui = ui, server = server)
編輯並執行程式碼