上传文本文件(ui)
与其在文本框中输入很长的文字,如果文本非常长,上传一个文本文件会更方便。
在 Shiny 应用中上传文件可以使用 fileInput()。
本练习是课程的一部分
案例研究:使用 R 的 Shiny 构建 Web 应用
练习说明
在 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)