【发布时间】:2019-12-22 21:32:52
【问题描述】:
我希望能够在每次单击“添加单词”/“删除单词”按钮时添加或删除新单词。但我希望应用程序保存以前添加/删除的单词。例如,如果我添加 'hello' 作为我的第一个单词,然后添加 'bye',我希望我的单词向量是 ['hello', 'bye']。如果我然后删除'hello',我的向量应该是['bye']
这是我迄今为止能够实现的目标
# Define UI ----------
ui <- fluidPage(
# Sidebar panel
sidebarLayout(
sidebarPanel(
selectInput('addrm',
label = h3('Remove or add words'),
choices = list('Remove words' = 1,
'Add words' = 2)),
textInput('words',
label = 'You can introduce multiple words separated by comma',
placeholder = 'Enter words...'),
uiOutput('button')
),
# Main panel
mainPanel(
textOutput('removeWords')
)
)
)
# Define server logic required ------------
server <- function(input, output){
output$button <- renderUI({
if (input$addrm == 1){
actionButton('button', label = 'Remove words')
} else{
actionButton('button', label = 'Add words')
}
})
stopwords <- c()
output$removeWords <- renderText({
input$button
isolate({ # Only runs when the button is clicked
stopwords <- unique(c(stopwords, unlist(strsplit(gsub(' ', '', input$words), ','))))
})
})
}
# Run the application
shinyApp(ui = ui, server = server)
【问题讨论】: