Instead of changing options
, we can simply use signif
to set our required number of digits. The following mini app can be modified as necessary to work for plot titles.
library(shiny)
ui <- fluidPage(
fluidRow(
column(6,
numericInput(
"hello_options",
label = "Number",
value = 3.145677177118
)),
column(6,
numericInput("digits",
label = "Digits",
value = 4
)
)
),
textOutput("out_text")
)
server <- function(input, output, server){
output$out_text <- renderText(
signif(input$hello_options, digits = input$digits)
)
}
shinyApp(ui = ui, server = server)
If you want to format
to scientific, then change your server to this. Note however that this gives you characters that should be converted back.
server <- function(input, output, server){
output$out_text <- renderText(
format(signif(input$hello_options, digits = input$digits),
scientific = TRUE)
)
}