Selection between master and children lost (non reproducible error, datas are from database)
I've created DT tables with links between master table, and child tables, which has child table etc...
I click on table master and I go from table to tables. And sometimes the initial selection is lost.
The initial goal was to have 2 database, archive and present time. I have a radio button to switch between the 2 database. So I have to put in all reactive function a function to reconnect or not to the correct chosen database.
Is a question for stackoverflow or a bug ?
This is for a big application.
But I have the same issue for a simple (old) application without DT and without reconnection between database.
The simple and the big Shiny applications are multi-user and each user could use multi-tab on their browser.
Thanks in advance :)
My structure of the big application:
server.R
database_name_decale<-"blabla_decale"
database_name_archive<-"blabla_archive"
connexion_bdd_odbc_decale_txt <- paste0('driver={ODBC Driver 17 for SQL Server};server=blabla;database=',database_name_decale,';uid=xxx;pwd=xxx;')
connexion_bdd_odbc_archive_txt <- paste0('driver={ODBC Driver 17 for SQL Server};server=blabla;database=',database_name_archive,';uid=xx;pwd=xx;')
...
shinyServer(function(input, output, session) {
react <- reactiveValues( connexion_bdd = 0)
observeEvent(
c(
input$radiob.ChoixBase
),
{
Init_cnx_bdd.fct_react (input,output,session, change_base= TRUE)
})
...
observeEvent(input$NavTabPanels, {
Init_cnx_bdd.fct_react (input,output,session, change_base= FALSE)
if (input$NavTabPanels=="My_Menu") {
...
My_Menu_maitre.tab.fct_react (input,output,session)
}
})
...
My_Menu_maitre.tab.fct_react <- function (input,output,session) {
...
detail.table <- reactive({
Init_cnx_bdd.fct_react (input,output,session, change_base = FALSE)
input_appelant= input$My_Menu_maitre_rows_selected
validate(
need(!is.null(input_appelant) , "Select a line from master")
)
res<- data.frame()
table_details <-subset( My_Menu_maitre.table()[as.integer(input_appelant), ],
select=c("id_num"))
res<- detail.reqSQL.fct (react$connexion_bdd,as.data.frame(table_details))
return(res)
})
...
sub_detail.table <- reactive({...})
...
sub_sub_detail.table <- reactive({...})
...
sub_sub_sub_detail.table <- reactive({...})
With this function
Init_cnx_bdd.fct_react <- function (input,output,session, change_base) {
req(react$connexion_bdd)
if(input$radiob.ChoixBase == "BaseActuelle") {
output$BaseCouranteTxt <-renderText({"Actuelle"})
if (change_base==TRUE) {
tryCatch(
{
odbcClose(react$connexion_bdd)
},
error=function(e) { # print("e")
},
warning=function(w) { # print("w")
}
)
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_decale_txt)
} else {
tryCatch(
{
odbcGetInfo(react$connexion_bdd)
},
error=function(e) { print("e")
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_decale_txt)
},
warning=function(w) { print("w")
}
)
}
}
if(input$Technique.Connexions.radiob.ChoixBase == "BaseArchive") {
output$Home.Technique.BaseCouranteTxt <-renderText({"Archive"})
if (change_base==TRUE) {
tryCatch(
{
odbcClose(react$connexion_bdd)
},
error=function(e) { #print("e")
},
warning=function(w) { # print("w")
}
)
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_archive_txt)
} else {
tryCatch(
{
odbcGetInfo(react$connexion_bdd)
},
error=function(e) { # print("e")
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_archive_txt)
},
warning=function(w) { # print("w")
}
)
}
}
}
My structure of the little application:
server.R
connexion_bdd_odbc_txt='driver={ODBC Driver 11 for SQL Server};server=xxx;database=blabla_decale;uid=xx;pwd=xxx;'
...
shinyServer(function(input, output,session) {
...
table.brut<-reactive({
connexion_bdd <- odbcDriverConnect(connexion_bdd_odbc_txt, readOnly = TRUE)
table<-sqlQuery(connexion_bdd, "SELECT * FROM blabla")
odbcClose(connexion_bdd)
table<-as.data.frame(table)
return(table)
})
...
and other tables and reactive function, not of the DT package, and a few linked between them.
r database shiny reactive-programming
add a comment |
I've created DT tables with links between master table, and child tables, which has child table etc...
I click on table master and I go from table to tables. And sometimes the initial selection is lost.
The initial goal was to have 2 database, archive and present time. I have a radio button to switch between the 2 database. So I have to put in all reactive function a function to reconnect or not to the correct chosen database.
Is a question for stackoverflow or a bug ?
This is for a big application.
But I have the same issue for a simple (old) application without DT and without reconnection between database.
The simple and the big Shiny applications are multi-user and each user could use multi-tab on their browser.
Thanks in advance :)
My structure of the big application:
server.R
database_name_decale<-"blabla_decale"
database_name_archive<-"blabla_archive"
connexion_bdd_odbc_decale_txt <- paste0('driver={ODBC Driver 17 for SQL Server};server=blabla;database=',database_name_decale,';uid=xxx;pwd=xxx;')
connexion_bdd_odbc_archive_txt <- paste0('driver={ODBC Driver 17 for SQL Server};server=blabla;database=',database_name_archive,';uid=xx;pwd=xx;')
...
shinyServer(function(input, output, session) {
react <- reactiveValues( connexion_bdd = 0)
observeEvent(
c(
input$radiob.ChoixBase
),
{
Init_cnx_bdd.fct_react (input,output,session, change_base= TRUE)
})
...
observeEvent(input$NavTabPanels, {
Init_cnx_bdd.fct_react (input,output,session, change_base= FALSE)
if (input$NavTabPanels=="My_Menu") {
...
My_Menu_maitre.tab.fct_react (input,output,session)
}
})
...
My_Menu_maitre.tab.fct_react <- function (input,output,session) {
...
detail.table <- reactive({
Init_cnx_bdd.fct_react (input,output,session, change_base = FALSE)
input_appelant= input$My_Menu_maitre_rows_selected
validate(
need(!is.null(input_appelant) , "Select a line from master")
)
res<- data.frame()
table_details <-subset( My_Menu_maitre.table()[as.integer(input_appelant), ],
select=c("id_num"))
res<- detail.reqSQL.fct (react$connexion_bdd,as.data.frame(table_details))
return(res)
})
...
sub_detail.table <- reactive({...})
...
sub_sub_detail.table <- reactive({...})
...
sub_sub_sub_detail.table <- reactive({...})
With this function
Init_cnx_bdd.fct_react <- function (input,output,session, change_base) {
req(react$connexion_bdd)
if(input$radiob.ChoixBase == "BaseActuelle") {
output$BaseCouranteTxt <-renderText({"Actuelle"})
if (change_base==TRUE) {
tryCatch(
{
odbcClose(react$connexion_bdd)
},
error=function(e) { # print("e")
},
warning=function(w) { # print("w")
}
)
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_decale_txt)
} else {
tryCatch(
{
odbcGetInfo(react$connexion_bdd)
},
error=function(e) { print("e")
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_decale_txt)
},
warning=function(w) { print("w")
}
)
}
}
if(input$Technique.Connexions.radiob.ChoixBase == "BaseArchive") {
output$Home.Technique.BaseCouranteTxt <-renderText({"Archive"})
if (change_base==TRUE) {
tryCatch(
{
odbcClose(react$connexion_bdd)
},
error=function(e) { #print("e")
},
warning=function(w) { # print("w")
}
)
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_archive_txt)
} else {
tryCatch(
{
odbcGetInfo(react$connexion_bdd)
},
error=function(e) { # print("e")
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_archive_txt)
},
warning=function(w) { # print("w")
}
)
}
}
}
My structure of the little application:
server.R
connexion_bdd_odbc_txt='driver={ODBC Driver 11 for SQL Server};server=xxx;database=blabla_decale;uid=xx;pwd=xxx;'
...
shinyServer(function(input, output,session) {
...
table.brut<-reactive({
connexion_bdd <- odbcDriverConnect(connexion_bdd_odbc_txt, readOnly = TRUE)
table<-sqlQuery(connexion_bdd, "SELECT * FROM blabla")
odbcClose(connexion_bdd)
table<-as.data.frame(table)
return(table)
})
...
and other tables and reactive function, not of the DT package, and a few linked between them.
r database shiny reactive-programming
add a comment |
I've created DT tables with links between master table, and child tables, which has child table etc...
I click on table master and I go from table to tables. And sometimes the initial selection is lost.
The initial goal was to have 2 database, archive and present time. I have a radio button to switch between the 2 database. So I have to put in all reactive function a function to reconnect or not to the correct chosen database.
Is a question for stackoverflow or a bug ?
This is for a big application.
But I have the same issue for a simple (old) application without DT and without reconnection between database.
The simple and the big Shiny applications are multi-user and each user could use multi-tab on their browser.
Thanks in advance :)
My structure of the big application:
server.R
database_name_decale<-"blabla_decale"
database_name_archive<-"blabla_archive"
connexion_bdd_odbc_decale_txt <- paste0('driver={ODBC Driver 17 for SQL Server};server=blabla;database=',database_name_decale,';uid=xxx;pwd=xxx;')
connexion_bdd_odbc_archive_txt <- paste0('driver={ODBC Driver 17 for SQL Server};server=blabla;database=',database_name_archive,';uid=xx;pwd=xx;')
...
shinyServer(function(input, output, session) {
react <- reactiveValues( connexion_bdd = 0)
observeEvent(
c(
input$radiob.ChoixBase
),
{
Init_cnx_bdd.fct_react (input,output,session, change_base= TRUE)
})
...
observeEvent(input$NavTabPanels, {
Init_cnx_bdd.fct_react (input,output,session, change_base= FALSE)
if (input$NavTabPanels=="My_Menu") {
...
My_Menu_maitre.tab.fct_react (input,output,session)
}
})
...
My_Menu_maitre.tab.fct_react <- function (input,output,session) {
...
detail.table <- reactive({
Init_cnx_bdd.fct_react (input,output,session, change_base = FALSE)
input_appelant= input$My_Menu_maitre_rows_selected
validate(
need(!is.null(input_appelant) , "Select a line from master")
)
res<- data.frame()
table_details <-subset( My_Menu_maitre.table()[as.integer(input_appelant), ],
select=c("id_num"))
res<- detail.reqSQL.fct (react$connexion_bdd,as.data.frame(table_details))
return(res)
})
...
sub_detail.table <- reactive({...})
...
sub_sub_detail.table <- reactive({...})
...
sub_sub_sub_detail.table <- reactive({...})
With this function
Init_cnx_bdd.fct_react <- function (input,output,session, change_base) {
req(react$connexion_bdd)
if(input$radiob.ChoixBase == "BaseActuelle") {
output$BaseCouranteTxt <-renderText({"Actuelle"})
if (change_base==TRUE) {
tryCatch(
{
odbcClose(react$connexion_bdd)
},
error=function(e) { # print("e")
},
warning=function(w) { # print("w")
}
)
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_decale_txt)
} else {
tryCatch(
{
odbcGetInfo(react$connexion_bdd)
},
error=function(e) { print("e")
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_decale_txt)
},
warning=function(w) { print("w")
}
)
}
}
if(input$Technique.Connexions.radiob.ChoixBase == "BaseArchive") {
output$Home.Technique.BaseCouranteTxt <-renderText({"Archive"})
if (change_base==TRUE) {
tryCatch(
{
odbcClose(react$connexion_bdd)
},
error=function(e) { #print("e")
},
warning=function(w) { # print("w")
}
)
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_archive_txt)
} else {
tryCatch(
{
odbcGetInfo(react$connexion_bdd)
},
error=function(e) { # print("e")
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_archive_txt)
},
warning=function(w) { # print("w")
}
)
}
}
}
My structure of the little application:
server.R
connexion_bdd_odbc_txt='driver={ODBC Driver 11 for SQL Server};server=xxx;database=blabla_decale;uid=xx;pwd=xxx;'
...
shinyServer(function(input, output,session) {
...
table.brut<-reactive({
connexion_bdd <- odbcDriverConnect(connexion_bdd_odbc_txt, readOnly = TRUE)
table<-sqlQuery(connexion_bdd, "SELECT * FROM blabla")
odbcClose(connexion_bdd)
table<-as.data.frame(table)
return(table)
})
...
and other tables and reactive function, not of the DT package, and a few linked between them.
r database shiny reactive-programming
I've created DT tables with links between master table, and child tables, which has child table etc...
I click on table master and I go from table to tables. And sometimes the initial selection is lost.
The initial goal was to have 2 database, archive and present time. I have a radio button to switch between the 2 database. So I have to put in all reactive function a function to reconnect or not to the correct chosen database.
Is a question for stackoverflow or a bug ?
This is for a big application.
But I have the same issue for a simple (old) application without DT and without reconnection between database.
The simple and the big Shiny applications are multi-user and each user could use multi-tab on their browser.
Thanks in advance :)
My structure of the big application:
server.R
database_name_decale<-"blabla_decale"
database_name_archive<-"blabla_archive"
connexion_bdd_odbc_decale_txt <- paste0('driver={ODBC Driver 17 for SQL Server};server=blabla;database=',database_name_decale,';uid=xxx;pwd=xxx;')
connexion_bdd_odbc_archive_txt <- paste0('driver={ODBC Driver 17 for SQL Server};server=blabla;database=',database_name_archive,';uid=xx;pwd=xx;')
...
shinyServer(function(input, output, session) {
react <- reactiveValues( connexion_bdd = 0)
observeEvent(
c(
input$radiob.ChoixBase
),
{
Init_cnx_bdd.fct_react (input,output,session, change_base= TRUE)
})
...
observeEvent(input$NavTabPanels, {
Init_cnx_bdd.fct_react (input,output,session, change_base= FALSE)
if (input$NavTabPanels=="My_Menu") {
...
My_Menu_maitre.tab.fct_react (input,output,session)
}
})
...
My_Menu_maitre.tab.fct_react <- function (input,output,session) {
...
detail.table <- reactive({
Init_cnx_bdd.fct_react (input,output,session, change_base = FALSE)
input_appelant= input$My_Menu_maitre_rows_selected
validate(
need(!is.null(input_appelant) , "Select a line from master")
)
res<- data.frame()
table_details <-subset( My_Menu_maitre.table()[as.integer(input_appelant), ],
select=c("id_num"))
res<- detail.reqSQL.fct (react$connexion_bdd,as.data.frame(table_details))
return(res)
})
...
sub_detail.table <- reactive({...})
...
sub_sub_detail.table <- reactive({...})
...
sub_sub_sub_detail.table <- reactive({...})
With this function
Init_cnx_bdd.fct_react <- function (input,output,session, change_base) {
req(react$connexion_bdd)
if(input$radiob.ChoixBase == "BaseActuelle") {
output$BaseCouranteTxt <-renderText({"Actuelle"})
if (change_base==TRUE) {
tryCatch(
{
odbcClose(react$connexion_bdd)
},
error=function(e) { # print("e")
},
warning=function(w) { # print("w")
}
)
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_decale_txt)
} else {
tryCatch(
{
odbcGetInfo(react$connexion_bdd)
},
error=function(e) { print("e")
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_decale_txt)
},
warning=function(w) { print("w")
}
)
}
}
if(input$Technique.Connexions.radiob.ChoixBase == "BaseArchive") {
output$Home.Technique.BaseCouranteTxt <-renderText({"Archive"})
if (change_base==TRUE) {
tryCatch(
{
odbcClose(react$connexion_bdd)
},
error=function(e) { #print("e")
},
warning=function(w) { # print("w")
}
)
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_archive_txt)
} else {
tryCatch(
{
odbcGetInfo(react$connexion_bdd)
},
error=function(e) { # print("e")
react$connexion_bdd<-odbcDriverConnect(connexion_bdd_odbc_archive_txt)
},
warning=function(w) { # print("w")
}
)
}
}
}
My structure of the little application:
server.R
connexion_bdd_odbc_txt='driver={ODBC Driver 11 for SQL Server};server=xxx;database=blabla_decale;uid=xx;pwd=xxx;'
...
shinyServer(function(input, output,session) {
...
table.brut<-reactive({
connexion_bdd <- odbcDriverConnect(connexion_bdd_odbc_txt, readOnly = TRUE)
table<-sqlQuery(connexion_bdd, "SELECT * FROM blabla")
odbcClose(connexion_bdd)
table<-as.data.frame(table)
return(table)
})
...
and other tables and reactive function, not of the DT package, and a few linked between them.
r database shiny reactive-programming
r database shiny reactive-programming
edited Nov 22 '18 at 18:19
phili_b
asked Nov 15 '18 at 18:39
phili_bphili_b
9611
9611
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
It seems that I use the "anti-solution" (named by Joe Cheng in his video tutorial).
anti-solution
observe ({
df<-head(cars, input$nrows)
output$plot <- renderPlot(plot(df))
})
good solution
output$plot <- renderPlot({
plot(head(cars, input$nrows))
})
I am going to modify my code, it is solved.
https://github.com/rstudio/shiny/issues/2262
edit 17/1/2018
For information: the cause of lost selections was not only the use of "anti-solution". After the correction the issue was going on again a little.
I have replaced RODBC by DBI and RStudio/odbc, and the issue doesn't occur anymore.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325965%2fselection-between-master-and-children-lost-non-reproducible-error-datas-are-fr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It seems that I use the "anti-solution" (named by Joe Cheng in his video tutorial).
anti-solution
observe ({
df<-head(cars, input$nrows)
output$plot <- renderPlot(plot(df))
})
good solution
output$plot <- renderPlot({
plot(head(cars, input$nrows))
})
I am going to modify my code, it is solved.
https://github.com/rstudio/shiny/issues/2262
edit 17/1/2018
For information: the cause of lost selections was not only the use of "anti-solution". After the correction the issue was going on again a little.
I have replaced RODBC by DBI and RStudio/odbc, and the issue doesn't occur anymore.
add a comment |
It seems that I use the "anti-solution" (named by Joe Cheng in his video tutorial).
anti-solution
observe ({
df<-head(cars, input$nrows)
output$plot <- renderPlot(plot(df))
})
good solution
output$plot <- renderPlot({
plot(head(cars, input$nrows))
})
I am going to modify my code, it is solved.
https://github.com/rstudio/shiny/issues/2262
edit 17/1/2018
For information: the cause of lost selections was not only the use of "anti-solution". After the correction the issue was going on again a little.
I have replaced RODBC by DBI and RStudio/odbc, and the issue doesn't occur anymore.
add a comment |
It seems that I use the "anti-solution" (named by Joe Cheng in his video tutorial).
anti-solution
observe ({
df<-head(cars, input$nrows)
output$plot <- renderPlot(plot(df))
})
good solution
output$plot <- renderPlot({
plot(head(cars, input$nrows))
})
I am going to modify my code, it is solved.
https://github.com/rstudio/shiny/issues/2262
edit 17/1/2018
For information: the cause of lost selections was not only the use of "anti-solution". After the correction the issue was going on again a little.
I have replaced RODBC by DBI and RStudio/odbc, and the issue doesn't occur anymore.
It seems that I use the "anti-solution" (named by Joe Cheng in his video tutorial).
anti-solution
observe ({
df<-head(cars, input$nrows)
output$plot <- renderPlot(plot(df))
})
good solution
output$plot <- renderPlot({
plot(head(cars, input$nrows))
})
I am going to modify my code, it is solved.
https://github.com/rstudio/shiny/issues/2262
edit 17/1/2018
For information: the cause of lost selections was not only the use of "anti-solution". After the correction the issue was going on again a little.
I have replaced RODBC by DBI and RStudio/odbc, and the issue doesn't occur anymore.
edited Jan 17 at 16:20
answered Nov 22 '18 at 11:16
phili_bphili_b
9611
9611
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325965%2fselection-between-master-and-children-lost-non-reproducible-error-datas-are-fr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown