Closed clbenoit closed 4 years ago
I get the following error Warning: Error in [.data.frame: undefined columns selected
Hello,
You should avoid using callModule
in reactive context such as observeEvent
, you're trying to register the module twice, that's why it dont work.
You can do something like this outside the module, and only send to the module the reactive dataset chosen.
Here an example:
library(shiny)
library(esquisse)
server <- function(input, output, session) {
r_example_data <- callModule(
module = chooseDataServer,
id = "example_data",
launchOnStart = FALSE,
dataModule = "GlobalEnv"
)
r_upload_data <- callModule(
module = chooseDataServer,
id = "upload_data",
launchOnStart = FALSE,
dataModule = "ImportFile"
)
# r_data will be passed to esquisse module, its value contain the last dataset chosen by user
r_data <- reactiveValues(data = data.frame(), name = "")
observeEvent(r_example_data$data, {
r_data$data <- r_example_data$data
r_data$name <- r_example_data$name
})
observeEvent(r_upload_data$data, {
r_data$data <- r_upload_data$data
r_data$name <- r_upload_data$name
})
callModule(module = esquisserServer, id = "esquisse", data = r_data)
}
ui <- fluidPage(
# To align the 2 buttons
tags$div(
class = "btn-group btn-group-justified",
tags$div(
class = "btn-group",
chooseDataUI(id = "example_data", label = "Example datasets")
),
tags$div(
class = "btn-group",
chooseDataUI(id = "upload_data", label = "Upload my datasets")
)
),
esquisserUI(
id = "esquisse",
header = FALSE,
choose_data = FALSE,
container = esquisseContainer(height = "700px")
)
)
shinyApp(ui, server)
Victor
It is wonderfully working, thanks a lot Victor =)
Clément
Hi,
I would like to let the user choose himself between using example datasets and import his proper one.
I tried something like this :
Both options are working separately if i use them just after launching the app. But If i have already updated one of this dataType, I can't switch to the other option then....
Thank you so much for you help, Does anyone have and idea ?
Clément