library(shiny)
ui <- fluidPage(
titlePanel("Application"),
fluidRow(column(
width = 8,
downloadButton("mydownload"),
textInput("message", label = "", placeholder = "Type your message here."),
actionButton("send", "Send"), heading = "Smart Advisor", status = "primary"
))
)
# initialise a csv
mytempfile <- paste0(tempfile(), ".csv")
# write a header
write("event_no,message", file = mytempfile, append = FALSE)
server <- function(input, output, session) {
clearInput <- function() {
updateTextInput(session, "message", value = "")
}
observeEvent(input$send, {
write(paste0(input$send, ",", input$message),
file = mytempfile, append = TRUE
)
# Case 1
insertUI(
selector = "#message",
where = "beforeBegin",
ui = div(
class = "registration",
div(
class = "bubble",
wellPanel(
p("Please enter your Name")
)
)
)
)
if (grepl("^[a-zA-Z][a-zA-Z ]+[a-zA-Z]$", input$message, perl = T)) {
insertUI(
selector = "#message",
where = "beforeBegin",
ui = div(
class = "registration",
div(
class = "bubble",
wellPanel(
p(input$message),
p("Please enter your Number")
)
)
)
)
clearInput()
}
})
output$mydownload <- downloadHandler(
filename = function() {
paste("data-", Sys.Date(), ".csv", sep = "")
},
content = function(con) {
file.copy(mytempfile, con)
}
)
}
shinyApp(ui, server)