sten
March 8, 2019, 6:56pm
1
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?
sten
March 8, 2019, 7:01pm
3
My bad I just added the code. I just updated my question.
1 Like
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.
1 Like
sten
March 8, 2019, 7:11pm
5
So when I use textInput
and updateTextInput
I get this
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)
1 Like
sten
March 21, 2019, 2:43pm
7
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 \\$
2 Likes
system
Closed
May 14, 2019, 6:47pm
9
This topic was automatically closed 54 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.