Closed MaheshKumbhar closed 3 years ago
It's not clear to me whether this is an issue on sortable
or with your shiny app.
Please can you provide a minimal reproducible example, in the form of a minimal, self-contained shiny app that displays this behaviour?
Here is the minimal code. I am using mtcars as Ref dataset to upload the file, as I mentioned the column names in bucket_list.
library(dplyr)
library(shiny)
library(shinyBS)
library(sortable)
library(shinyWidgets)
library(tidyr)
library(tidyverse)
library(tidyselect)
ui = fluidPage(
sidebarPanel(
fileInput("file", "Choose CSV File", accept = c(".csv"))
),
mainPanel(
actionButton(inputId = "tabBut", label = "Customize"),
bsModal(id = "modalExample",title = 'Select Features and Re-Arrange ', #"Data Table",
trigger = "tabBut", size = "large",
radioButtons( 'radio', 'Select Action', choices =
list( 'Default' = 'Default', 'Custom' = 'Custom'),
selected = 'Default', inline = T ),
bucket_list(
header = "",
group_name = "bucket_list_group",
add_rank_list(
text = "Drag from here",
labels =
c("mpg","cyl", "disp",
"hp",'drat','wt','qsec','vs','am','gear','carb'),
input_id = "rank_list_1"
),
add_rank_list(
text = "To here", labels = NULL,input_id = "rank_list_2"
),orientation = 'horizontal'
)
),
DT::dataTableOutput('data')
))
server = function(input, output, session) {
rv <- reactiveValues(data=NULL)
df <- reactive({
infile <- input$file
if(is.null(infile))
return(NULL)
infile <- read.csv(infile$datapath,header = TRUE)
return(infile)
})
main_df <- reactive({
selected_action = input$radio
if(selected_action == 'Custom' ){
result <- df() %>%
select(all_of(input$rank_list_2))
}
else{
result <- df()
}
return(as.data.frame(result))
})
output$data <- DT::renderDataTable({
if(is.null(main_df())) return()
DT::datatable(main_df(),
filter = 'top', editable = FALSE, options = list(autoWidth = TRUE))
})
}
shinyApp(ui, server)
I have simplified your code example (see below) and ran the code. It seems to me that everything works as expected.
Can you please clarify your question?
You said:
It works on server local environment console but disconnect when I am running on RServer using link
What do you mean by "RServer"? What do you mean by "using link"?
library(shiny)
library(sortable)
library(shinyBS)
library(dplyr)
ui = fluidPage(
mainPanel(
actionButton(
inputId = "tabBut",
label = "Customize"
),
bsModal(
id = "modalExample",
title = 'Select Features and Re-Arrange ',
trigger = "tabBut",
radioButtons(
'radio',
'Select Action',
choices = c('Default', 'Custom'),
selected = 'Default',
inline = TRUE
),
bucket_list(
header = "",
group_name = "bucket_list_group",
add_rank_list(
text = "Drag from here",
labels =
c("mpg","cyl", "disp",
"hp",'drat','wt','qsec','vs','am','gear','carb'),
input_id = "rank_list_1"
),
add_rank_list(
text = "To here",
input_id = "rank_list_2"
),
orientation = 'horizontal'
)
),
DT::dataTableOutput('data')
))
server = function(input, output, session) {
df <- reactive({ mtcars })
main_df <- reactive({
selected_action = input$radio
if(selected_action == 'Custom' ){
df() %>%
select(all_of(input$rank_list_2))
}
else{
df()
}
})
output$data <- DT::renderDataTable({
req(main_df())
DT::datatable(
main_df(),
filter = 'top'
)
})
}
shinyApp(ui, server)
I am having Server where R is hosted which is responsible for all applications. If I am using my development window (hosted on Server) of RStudio to modify my code, the above code works fine, if I click button of Run App. But after I saved the changes and ran from URL (link) of application the application disconnect when this particular DT::renderDataTable steps triggered.
I am facing issues with DT::renderDataTable with reactive function (which I am using to select Drag and Drop columns to filter selected columns to show on UI). It works on server local environment console but disconnect when I am running on RServer using link. It breaks when it was trying to populate dataframe on UI. All package versions are same and I am using R 3.6.1. There are no Error logs in console while running on locally.
This was working fine few days back, but not working now.
Below is the snippet of code.