附加/删除“闪亮”中的输入文本(单词)而不会覆盖

时间:2019-12-22 13:14:30

标签: r shiny

我希望每次单击“添加单词” /“删除单词”按钮时都可以添加或删除新单词。但我希望该应用程序保存以前添加/删除的单词。例如,如果我在第一个单词中添加“ hello”,然后再添加“ bye”,则我希望单词的向量为['hello','bye']。如果再删除“ hello”,我的向量应为['bye']

这是我到目前为止所能实现的

with cte as
(
    .....
)
select * 
from cte;

1 个答案:

答案 0 :(得分:0)

没关系,我能够在以下post

中找到所需的内容

以防万一有人想要答案:


# 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')
    }
  })

  values <- reactiveValues()
  values$stopwords <- c()

  output$removeWords <- renderText({

    input$button
    isolate({ # Only runs when the button is clicked
      values$stopwords <- unique(c(values$stopwords, unlist(strsplit(gsub(' ', '', input$words), ',')))) 
    })
  })
}

# Run the application 
shinyApp(ui = ui, server = server)