我创建了一个应用,其中有两个actionButtons
ui.R
h4("First | Second "),
actionButton(inputId = "first",
label = "First"),
actionButton(inputId = "second",
label = "Second"),
这就是我的server.R
#create the datasetbased on the choice of "First" or "Second"
myDataSet <- reactiveValues(data = NULL)
#observer to see what is clicked. Decision is send to "reactiveValues"
observeEvent(input$first, {
myDataSet$data <- dataframe1
})
#observer to see what is clicked. Decision is send to "reactiveValues"
observeEvent(input$second, {
myDataSet$data <- dataframe2
})
取决于来自actionButton
的{{1}}来自dataframe1
的{{1}}或dataframe2
的输入。
如上所述:这是myDataSet
创建将保留reactiveValues()
的变量的方式吗?请注意,dataframes
中dataframes
发送的扩展(列/行)会有所不同。
答案 0 :(得分:1)
这是整个工作示例
ui <- fluidPage(
h4("First | Second "),
actionButton(inputId = "first", label = "First"),
actionButton(inputId = "second", label = "Second"),
htmlOutput("nrows")
)
server <- function(input, output, session) {
dataframe1 <- data.frame(c(1,2,3))
dataframe2 <- data.frame(c(1,2,3,4,5))
#create the datasetbased on the choice of "First" or "Second"
myDataSet <- reactiveValues(data = NULL)
#observer to see what is clicked. Decision is send to "reactiveValues"
observeEvent(input$first, {
myDataSet$data <- dataframe1
})
#observer to see what is clicked. Decision is send to "reactiveValues"
observeEvent(input$second, {
myDataSet$data <- dataframe2
})
output$nrows <- renderUI({
HTML(paste('dataframe rows:', nrow(myDataSet$data)))
})
}
shinyApp(ui, server)