反应性价值渲染

时间:2020-10-03 09:04:47

标签: shiny

我在这里遇到了小问题。当应用程序运行时,默认情况下,它将显示101,然后由用户selectinput更改值。下面是仓库

library(shiny)
library(DT)

ui <- fluidPage(
  tags$h3("Material switch examples"),
  
  selectInput("sel", "select number", choices = c("",1:100),selected = ""),
  dataTableOutput("df"),
  textOutput("df1")
)

server <- function(input, output, session) {
  num <- reactiveVal(c(101))
  
  observeEvent(input$sel, {
    num <- input$sel
  })
  
  
  # output$df <- DT::renderDataTable({
  #   datatable(data,caption = "Iris",options = list(dom = 'ft'),escape=FALSE, selection = list(mode = 'single',target = 'cell'))
  # })
  
  output$df1 <- renderText({
    as.numeric(num())
  })
}

shinyApp(ui, server)

2 个答案:

答案 0 :(得分:0)

<div className="product-list-item__imageSoldOut" style={{ backgroundImage: `url(${(product.thumbnail.url && product.thumbnail.url) || "images/no-photo.svg"})`, backgroundSize: "auto 100%" }} > <img src={soldOutThumb} /> </div> 的第二次出现将覆盖第一个(如在普通R代码中一样):

num

答案 1 :(得分:0)

尝试一下

library(shiny)
library(DT)

ui <- fluidPage(
  tags$h3("Material switch examples"),
  
  selectInput("sel", "select number", choices = c("",1:100), selected = NULL),
  dataTableOutput("df"),
  textOutput("df1")
)

server <- function(input, output, session) {
  num <- reactiveVal(101)
  
  observeEvent(input$sel, {
    num(req(input$sel))
  })

  output$df1 <- renderText({
    as.numeric(num())
  })
}

shinyApp(ui, server)