Format numericInput in R

I am trying to format the numeric input in an R shiny app just for display purpose. When I do that on load it shows the number and then the numericInput box goes blank.

library(shiny)

if(interactive()){
  shinyApp(
    ui <- fluidPage(
      mainPanel(
        numericInput("inp1", label = ("Total"), value = 11000000)
      )
    ),

    server <- function(input, output, session) {

      observe({
        updateNumericInput(session, "inp1", label = ("Total"),
                          paste("S", value = prettyNum(input$inp1, big.mark=",", scientific=FALSE)))
      })
    }
  )
}

hey @sten - it would be helpful if we had some context for this post - what type of error are you running into or what are you hoping to achieve?

My bad I just added the code. I just updated my question.

I think this is not possible with numericInput, because the value parameter has to be numeric, but you can do it with textInput and convert the value to numeric later.

So when I use textInput and updateTextInput I get this

image

The prefix is causing an infinite loop, try with something like this.

library(shiny)
library(stringr)
library(scales)

ui <- fluidPage(
    mainPanel(
        textInput("inp1", label = "Total", value = "110000")
    )
)

server <- function(input, output, session) {
    
    observe({
        if (!str_detect(input$inp1, "S ")) {
            updateTextInput(session, "inp1", "Total", 
                            value = number(as.numeric(input$inp1), prefix = "S ", big.mark = ","))
        }
    })
}

shinyApp(ui = ui, server = server)

When I change the prefix S as $ it get output as $ NA.

You need to change this line

if (!str_detect(input$inp1, "\\$"))

This is because $ is a metacharacter and needs to be escaped in the regular expression with \\$