How to render centralized text inputs in a window and save then? Customer Registration Example

Viewed 44

Well i trying to open a window by pressing a button to write some text inputs and submit to MySql table, like this example below, but i dont know how i centralize the texts inputs.

ATTEMPT

library(shinyWidgets)
library(shiny)
library(shinyjs)
library(RMariaDB)
shinyApp(
  ui = fluidPage(
    useShinyjs(), # Set up shinyjs
    actionButton("btn", "Costumer Registration"),
   
    
  ),
  server = function(input, output,session) {
#connect to MySQL
#localuserpassword= "PASSW"
#myconnect <- dbConnect(RMariaDB::MariaDB(), user='user', password=localuserpassword, dbname='name', host='localhost')
    

    observeEvent(input$btn, {  # open a window by pressing the "btn" button
      
      confirmSweetAlert(
        btn_labels = c("Cancel","Submit"),
        session = session,
        inputId = "SubmitCostumertoSQL",
        type = "info",
        title = paste0("Customer Registration"),
        danger_mode = F,
        closeOnClickOutside = T,
        showCloseButton =T,
        text = tags$div(
                        renderUI(textInput("name", "Name")),
                        renderUI(textInput("NRLE", "National Registry of Legal Entities")),
                        renderUI(textInput("address", "Address")),
        )
      )

    } )
    observeEvent(input$SubmitCostumertoSQL, {
#Send to MySQL    

      #querycostumer= paste("insert into TABLENAME(Name,NRLE,Addres)
      #      values('",input$name,"','",
       #     input$NRLE,"','",
        #    input$address,
         #   "')" ,sep = '') 
     
     #dbSendQuery(myconnect,querycostumer)
     
    })
    }
)

How to centralize the text input and save then into a object? enter image description here

1 Answers

Include align = 'center' in your div, e.g. text = tags$div(align = 'center',

textInput can also include placeholder text if you want to match the example more closely.

Minimal working example

library(shinyWidgets)
library(shiny)
library(shinyjs)

shinyApp(
    
ui = fluidPage(
    useShinyjs(),
    actionButton("btn", "Costumer Registration"),
),
    
server = function(input, output,session) {

    observeEvent(input$btn, {
        
        confirmSweetAlert(
            btn_labels = c("Cancel","Submit"),
            session = session,
            inputId = "SubmitCostumertoSQL",
            type = "info",
            title = paste0("Customer Registration"),
            danger_mode = F,
            closeOnClickOutside = T,
            showCloseButton =T,
            text = tags$div(align = 'center',
                renderUI(textInput("name", "Name")),
                renderUI(textInput("NRLE", "National Registry of Legal Entities")),
                renderUI(textInput("address", "Address")),
            )
        )
        
    })

})
Related