Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECharts2Shiny even treactive problem (data error) #60

Open
luomei308 opened this issue Jun 24, 2019 · 2 comments
Open

ECharts2Shiny even treactive problem (data error) #60

luomei308 opened this issue Jun 24, 2019 · 2 comments

Comments

@luomei308
Copy link

ECharts2Shiny seems not to process the reactive

library(shiny)
library(ECharts2Shiny)
library(DT)

ui <- fluidPage(# App title ----
titlePanel("Uploading Files"),

            sidebarLayout(
              sidebarPanel(
                fileInput(
                  "file1",
                  "Choose CSV File",
                  multiple = FALSE,
                  accept = c("text/csv",
                             "text/comma-separated-values,text/plain",
                             ".csv")
                ),
                actionButton("do", "RUN")
                
                # Horizontal line ----
              ),
              
              mainPanel(
                DT::dataTableOutput("mytable"),
                deliverChart(div_id = "echart"),
                plotOutput('basic')
              )
              
            ))

analysis <- function(data_up) {
expr <-
read.table(
data_up,
header = TRUE,
sep = "\t",
fill = TRUE,
row.names = 1
)
expr <- as.matrix(expr)
resu_list <- list(resu = expr[1:10, 1:3], exp = expr[1:100, 1:3])
}

server <- function(input, output) {
results <- eventReactive(input$do, {
inFile <- input$file1
if (is.null(inFile))
return(NULL)
analysis(inFile$datapath)
})

output$mytable <- DT::renderDataTable({
withProgress(
message = 'Calculation in progress',
detail = 'This may take a while...',
value = 0,
expr = {
df <- results()
result <- df$resu
}
)
DT::datatable(
result,
extensions = 'Buttons',
options = list(
language = list(url = '//cdn.datatables.net/plug-ins/1.10.11/i18n/English.json'),
searchHighlight = TRUE,
dom = 'lBfrtip',
scrollX = TRUE,
fixedColumns = list(leftColumns = 2, rightColumns = 1),
buttons = c('csv', 'excel', 'pdf'),
lengthMenu = c(10, 20, 50, -1)
)
)
})

output$basic <- renderPlot({
plot(results()$exp, type = 'l')

})

renderLineChart(
div_id = "echart",
data = results()$exp,
step = "null",
show.legend = FALSE,
show.tools = TRUE,
show.slider.axis.x = TRUE,
font.size.axis.x = 0.2
)

}
shinyApp(ui, server)

@XD-DENG
Copy link
Owner

XD-DENG commented Jun 24, 2019

Hi @luomei308 . Thanks for reporting the issue.

May you refer to https://github.com/XD-DENG/ECharts2Shiny/blob/master/examples/example-5%20Use%20Reactive%20Values/server.R first to see if it helps? Thanks.

@luomei308
Copy link
Author

library(shiny)
library(ECharts2Shiny)
library(DT)
ui <- fluidPage(# App title ----
titlePanel("Uploading Files"),

            sidebarLayout(
              sidebarPanel(
                fileInput(
                  "file1",
                  "Choose CSV File",
                  multiple = FALSE,
                  accept = c("text/csv",
                             "text/comma-separated-values,text/plain",
                             ".csv")
                ),
                actionButton("do", "RUN")
                
                # Horizontal line ----
              ),
              
              mainPanel(
                DT::dataTableOutput("mytable"),
                deliverChart(div_id = "echart"),
                plotOutput('basic')
              )
              
            ))

analysis <- function(data_up) {
expr <-
read.table(
data_up,
header = TRUE,
sep = "\t",
fill = TRUE,
row.names = 1
)
expr <- as.matrix(expr)
resu_list <- list(resu = expr[1:10, 1:3], exp = expr[1:100, 1:3])
}

server <- function(input, output) {
results <- eventReactive(input$do, {
inFile <- input$file1
if (is.null(inFile))
return(NULL)
analysis(inFile$datapath)
})

output$mytable <- DT::renderDataTable({
withProgress(
message = 'Calculation in progress',
detail = 'This may take a while...',
value = 0,
expr = {
df <- results()
result <- df$resu
}
)
DT::datatable(
result,
extensions = 'Buttons',
options = list(
language = list(url = '//cdn.datatables.net/plug-ins/1.10.11/i18n/English.json'),
searchHighlight = TRUE,
dom = 'lBfrtip',
scrollX = TRUE,
fixedColumns = list(leftColumns = 2, rightColumns = 1),
buttons = c('csv', 'excel', 'pdf'),
lengthMenu = c(10, 20, 50,-1)
)
)
})

output$basic <- renderPlot({
plot(results()$exp, type = 'l')

})

observeEvent(results()$exp, {
renderLineChart(
div_id = "echart",
data = results()$exp,
step = "null",
show.legend = FALSE,
show.tools = TRUE,
show.slider.axis.x = TRUE,
font.size.axis.x = 0.2
)
})

}
shinyApp(ui, server)

Hello,
renderLineChart seems not to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants