2017-10-16 71 views
0

我試圖創建一個讀取一些參數(如textInput)並相應地更改數據框的小應用程序,但它看起來並沒有真正讀取輸入。在Shiny應用程序中輸入文字問題

如果我打開應用程序,插入參數,然後單擊提交什麼也沒有發生,我仍然無法看到數據幀。我也嘗試使用observeEvent,但那也沒有工作。我不知道爲什麼,因爲我使用相同的代碼結構的selectInput和一切工作正常。

我創建了一個小的可重複的例子:

library(shiny) 
library(shinydashboard) 
library(data.table) 
library(DT) 
library("RJDBC") 
library("RODBC") 

## 
ui <- shinyUI(pageWithSidebar(
    headerPanel("DBC Comparison"), 
    sidebarPanel(
    textInput("Database_1", "Database 1"), 
    textInput("Database_2", "Database2"), 
    textInput("odbc", "ODBC Name"), 
    textInput("user", "Username"), 
    textInput("pwd", "password" 
      ), 
    actionButton(
     inputId = "submit_loc", 
     label = "Submit") 
), 

    mainPanel(
    DT::dataTableOutput("table"), 
    div(style = 'overflow-x: scroll', tableOutput('table')) 

) 
)) 


## 
server <- shinyServer(function(input, output, session) { 


    Difference = reactive({ 

    df <- data.frame(user = input$user, pwd =input$pwd, db2=input$Database_2, db1=input$Database_1) 
     return(list(df=df)) 

    }) 


    output$table = DT::renderDataTable(server = TRUE,{ 
    DT::datatable(Difference, 
        extensions=c("Buttons",'Scroller'), 
        options = list(dom = 'Bfrtip', 
           buttons = c('copy', 'csv', 
              'excel', 'pdf', 
              'print'), 
           scrollY = 500, 
           scroller = TRUE) 
    ) 
    }) 

}) 
## 
shinyApp(ui = ui, server = server) 

回答

2

好像問題可能是:

div(style = 'overflow-x: scroll', tableOutput('table')) 

所以我評論說出來,也有指Difference爲​​在數據表調用。並作出該數據的更改取決於eventReactive(input$submit_loc,{expr})

library(shiny) 
library(shinydashboard) 
library(data.table) 
library(DT) 
library("RJDBC") 
library("RODBC") 

## 
ui <- shinyUI(pageWithSidebar(
    headerPanel("DBC Comparison"), 
    sidebarPanel(
    textInput("Database_1", "Database 1"), 
    textInput("Database_2", "Database2"), 
    textInput("odbc", "ODBC Name"), 
    textInput("user", "Username"), 
    textInput("pwd", "password" 
    ), 
    actionButton(
     inputId = "submit_loc", 
     label = "Submit") 
), 

    mainPanel(
    DT::dataTableOutput("table")#, 
    #div(style = 'overflow-x: scroll', tableOutput('table')) 

) 
)) 


## 
server <- shinyServer(function(input, output, session) { 


    Difference = eventReactive(input$submit_loc,{ 

    df <- data.frame(user = input$user, pwd =input$pwd, db2=input$Database_2, db1=input$Database_1) 
    return(df) 

    }) 


    output$table = DT::renderDataTable(server = TRUE,{ 
    DT::datatable(Difference(), 
        extensions=c("Buttons",'Scroller'), 
        options = list(dom = 'Bfrtip', 
           buttons = c('copy', 'csv', 
              'excel', 'pdf', 
              'print'), 
           scrollY = 500, 
           scroller = TRUE) 
    ) 
    }) 

}) 
## 
shinyApp(ui = ui, server = server) 
相關問題