0
私は以下のようなアプリを持っています。私は、ファイルのアップロードからデータを読み込むか、組み込みのデータを使用したいと思います。私はアクションボタンを置くことができたと思って、誰かがそれを打つと、入力データが上がり、次のレベルに行く。私の問題は後で私の実際のアプリで、selectInput
のようなウィジェットの一部を更新する必要があり、ユーザーがアップロードされたデータを使うのか組み込みのものを使うのかを決めるまでは空白にしたい。アップロードされたデータの代わりにビルトインデータを使用する方法
library(shiny)
x <- mtcars
ui <- fluidPage(
fileInput(inputId = "uploadcsv", "", accept = '.csv'),
actionButton(inputId = "a", label = "action button"),
selectInput("select",label = h3("Select box"),choices = "",selected = 1)
)
server <- function(input, output, session) {
data <- reactive({
infile <- input$uploadcsv
if (is.null(infile))
return(NULL)
read.csv(infile$datapath, header = TRUE, sep = ",")
})
DataToUse <- NULL
observe(!is.null(input$uploadedcsv),
DataToUse <- data()
)
observeEvent(input$a,
DataToUse <- x
)
observe({
req(DataToUse)
if (max(DataToUse$cyl) %% 4 == 0){
numberofinterval <- max(DataToUse$cyl) %/% 4
} else {
numberofinterval <- (max(DataToUse$cyl) %/% 4)+1
}
NumPeriod <- seq(0, numberofinterval)
updateSelectInput(session, inputId = "select",
choices = NumPeriod,
selected = NumPeriod)
})
}
shinyApp(ui = ui, server = server)