We are allowing the users to update anyone of the 3 inputs. Shiny calculates ratio among them and display in %. However, this displayed value is editable in shiny.
Since the displayed value is necessary for further calculation in the code, this behavior is undesirable.
Therefore, could someone help to display the values in % but allow the user not to edit them.
Please find below reprex code. Tried
- Render as print and sprint but hard to format
- Disabled the renderUI but then code didnt function as renderUI didnt run.
library(shiny)
ui <- fluidPage(
column(6,
tags$h2("Allow the user to change only here"),
numericInput("valueA", "Value1", value = .333, min = 0, max = 1, step = .1),
numericInput("valueB", "Value2", value = .333, min = 0, max = 1, step = .1),
numericInput("valueC", "Value3", value = .333, min = 0, max = 1, step = .1),
verbatimTextOutput("result")
),
column(6,
uiOutput("ui")
)
)
server <- function(input, output, session) {
output$ui <- renderUI( {
tagList(
tags$h2("Display in % but dont allow user to change here"),
numericInput("obs1", "Label1", value = 100 * (input$valueA / (input$valueA + input$valueB + input$valueC))),
numericInput("obs2", "Label2", value = 100 * (input$valueB / (input$valueA + input$valueB + input$valueC))),
numericInput("obs3", "Label3", value = 100 * (input$valueC / (input$valueA + input$valueB + input$valueC)))
)
})
# Since the below option is hard to render like above
# output$result <- renderPrint({
# print(sprintf("A=%.3f, B = %.3f",
# input$obs1,input$obs2))
# })
#### Code to use the values from obs1,obs2,obs3....
}
shinyApp(ui, server)
Basically, 3 values where users can edit and ratios (%) should be displayed. However these percentages shouldn't be editable.