ABH*_*WAJ 1 shiny shiny-reactivity
我的代码:-
library(shiny)
ui <- fluidPage(
titlePanel("Find square of x"),
numericInput("x","x:",5),
uiOutput("y")
)
server <- function(input, output){
output$y <- renderUI({
numericInput("y","Square of x:",input$x * input$x)
})
}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)
在此应用程序中,用户可以更改输出的值"Square of x"。有什么方法可以防止这种情况(意味着可以在输出中禁用用户输入)。
或者,如果用户修改输出"Square of x"而不是输入,"x"也会相应地发生变化。
是的,我们可以用shinyjs它:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
titlePanel("Find square of x"),
numericInput("x","x:",5),
numericInput("y","Square of x:",NULL)
)
server <- function(input, output,session){
observeEvent(input$x,{
updateNumericInput(session, "y", value = input$x * input$x)
disable("y")
})
}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1230 次 |
| 最近记录: |