这个问题关系到这一个.这两者可以生成相同的功能,但实现略有不同.一个显着的区别是a reactiveValue是一个可以有多个值的容器,比如input$.在闪亮的文档中,功能通常使用reactive(),但在大多数情况下我觉得reactiveValues()更方便.这里有捕获吗?我可能没有注意到这两者之间是否存在其他重大差异?这两个代码片段是否相同?
查看 使用以下实现的相同示例代码:
反应性表达:
library(shiny)
ui <- fluidPage(
shiny::numericInput(inputId = 'n',label = 'n',value = 2),
shiny::textOutput('nthValue'),
shiny::textOutput('nthValueInv')
)
fib <- function(n) ifelse(n<3, 1, fib(n-1)+fib(n-2))
server<-shinyServer(function(input, output, session) {
currentFib <- reactive({ fib(as.numeric(input$n)) })
output$nthValue <- renderText({ currentFib() })
output$nthValueInv <- renderText({ 1 / currentFib() })
})
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)反应值:
library(shiny)
ui <- fluidPage(
shiny::numericInput(inputId = 'n',label = 'n',value = 2),
shiny::textOutput('nthValue'),
shiny::textOutput('nthValueInv') …Run Code Online (Sandbox Code Playgroud)我是一个新手程序员,如果我不清楚或遗漏相关信息,请原谅。我编写了一个闪亮的应用程序,它从另一组代码导入数据帧。我想使用应用程序中的用户输入更新该数据框。我已经使用下面的代码将数据帧作为反应变量上传:
数据
current.shiny <- data.frame("Task" = as.character(c("Task 1", "Task 2", "Task 3")), "Completed" = as.character(c("Yes", "NO", "Yes")),"Date.Completed" = as.Date(c("2020-10-19","2020-10-20", "2020-10-21")))
Run Code Online (Sandbox Code Playgroud)
用户界面
ui<- fluidPage(
# Application title
titlePanel("Week of 11.02.2020"),
# Sidebar with reactive inputs
sidebarLayout(
sidebarPanel(
selectInput(inputId = "task.choice", label = "Task",
choices = c(as.list(current.shiny$Task))),
selectInput(inputId = "completed", label = "Completed?",
choices = c("Yes" = "Yes", "No" = "No")),
dateInput(inputId = "date.completed", label ="Date Completed"),
actionButton("update","Update Sheet")
),
# a table of reactive outputs
mainPanel(
mainPanel(
#DT::dataTableOutput("dt_table", width = 500) …Run Code Online (Sandbox Code Playgroud)