【问题标题】:R Shiny - Passing User Input as Global StringR Shiny - 将用户输入作为全局字符串传递
【发布时间】:2018-11-10 17:40:30
【问题描述】:

如何接收用户输入并将其存储为 server.R 中的环境字符串?

这是一个示例(会产生错误):

library(shiny)

# Define the UI

n <- 100

ui <- bootstrapPage(
  numericInput('n', 'Number of obs', n),
  textOutput('count_new')
)

# Define the server code
server <- function(input, output) {

  count <- as.numeric(renderText({input$n}))
  output$count_new <- renderText({count/10})

}

# Return a Shiny app object
shinyApp(ui = ui, server = server)

【问题讨论】:

    标签: r shiny render reactive


    【解决方案1】:

    找到了解决办法。关键是在输入前使用reactive。然后可以调用该变量,后跟()

    library(shiny)
    
    # Define the UI
    
    n <- 100
    
    ui <- bootstrapPage(
      numericInput('n', 'Number of obs', n),
      textOutput('count_new')
    )
    
    # Define the server code
    server <- function(input, output) {
    
      count <- reactive({input$n})
      output$count_new <- renderText({count()/10})
    
    }
    
    # Return a Shiny app object
    shinyApp(ui = ui, server = server)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-18
      • 1970-01-01
      • 2016-10-13
      • 2020-07-21
      • 2021-08-26
      • 2020-03-15
      • 2015-05-08
      相关资源
      最近更新 更多