【发布时间】:2019-08-01 08:16:27
【问题描述】:
我正在开发一个闪亮的应用程序,用户可以在其中上传自己的数据并获取一些图表和统计数据。但是,我还想包含一个示例数据集,如果用户按下特定按钮,则会使用该示例数据集。重要的是,绘图应该是反应性的,以便用户在单击“改用示例数据”按钮或上传新文件时获得更新的绘图。我试图在这里尽可能地重新创建我当前的覆盖数据对象的方法,但是简单地定义数据对象两次并不会以我希望的方式覆盖数据。任何建议表示赞赏。
library(shiny)
# UI
ui <- fluidPage(
# Application title
titlePanel("Reproducible Example"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
fileInput("Upload", "Upload your own Data"),
actionButton("Example", "Use Example Data instead")
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("hist")
)
)
)
# Server Logic
server <- function(input, output) {
data <- eventReactive(input$Upload,{input$Upload})
data <- eventReactive(input$Example, {faithful$eruptions})
output$hist <- renderPlot({hist(data())})
}
# Run the application
shinyApp(ui = ui, server = server)
【问题讨论】: