R 两次指定被动表达式将忽略第一个表达式
闪亮初学者:我想根据点击的动作按钮加载不同的数据集。因为从那时起,对任何数据集的处理都是相同的,所以我想将它们存储在相同的反应式表达式中,这里是R 两次指定被动表达式将忽略第一个表达式,r,shiny,reactive,R,Shiny,Reactive,闪亮初学者:我想根据点击的动作按钮加载不同的数据集。因为从那时起,对任何数据集的处理都是相同的,所以我想将它们存储在相同的反应式表达式中,这里是dataset() 请参阅我的代码: library(shiny) ui <- shinyUI(fluidPage( sidebarLayout( sidebarPanel( actionButton("gohere", "dataset1&q
dataset()
请参阅我的代码:
library(shiny)
ui <- shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
actionButton("gohere", "dataset1"),
actionButton("gothere", "dataset2")
),
mainPanel(
tableOutput("dataset")
),
)
)
)
server <- function(input, output) {
dataset <- eventReactive(input$gohere, {
mtcars
})
dataset <- eventReactive(input$gothere, {
cars
})
output$dataset <- renderTable({
dataset()
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
ui这与普通的R编程类似:您的两个无功导体是同名的R对象,因此第二个对象覆盖第一个对象
您可以使用无功值和一些观察者:
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
actionButton("gohere", "dataset1"),
actionButton("gothere", "dataset2")
),
mainPanel(
tableOutput("dataset")
),
)
)
server <- function(input, output) {
dataset <- reactiveVal(mtcars)
observeEvent(input$gohere, {
dataset(mtcars)
})
observeEvent(input$gothere, {
dataset(cars)
})
output$dataset <- renderTable({
dataset()
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
ui这与普通的R编程类似:您的两个无功导体是同名的R对象,因此第二个对象覆盖第一个对象
您可以使用无功值和一些观察者:
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
actionButton("gohere", "dataset1"),
actionButton("gothere", "dataset2")
),
mainPanel(
tableOutput("dataset")
),
)
)
server <- function(input, output) {
dataset <- reactiveVal(mtcars)
observeEvent(input$gohere, {
dataset(mtcars)
})
observeEvent(input$gothere, {
dataset(cars)
})
output$dataset <- renderTable({
dataset()
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
谢谢你的回答。我想这可能就是原因,这就是为什么我尝试使用exists()
和is.null()
来查看在第二次eventReactive()
之后dataset()
会发生什么,但它没有输出任何内容。在第二个actionButton上,我得到了输出TRUE和FALSE,单击第一个按钮没有输出。所以问题是:它是用什么覆盖它的?谢谢你的回答。我想这可能就是原因,这就是为什么我尝试使用exists()
和is.null()
来查看在第二次eventReactive()
之后dataset()
会发生什么,但它没有输出任何内容。在第二个actionButton上,我得到了输出TRUE和FALSE,单击第一个按钮没有输出。所以问题是:它用什么覆盖了它?