2017-10-16 12 views
0

Ich versuche, eine kleine App, die einige Parameter liest (wie textInput) und ändert den Datenrahmen entsprechend, aber es sieht aus wie es ist nicht wirklich liest die Eingabe.Problem mit der Texteingabe in Shiny App

Wenn ich die App öffnen, fügen Sie die Parameter ein, und klicken Sie dann auf Senden nichts passiert, ich kann immer noch nicht sehen, den Datenrahmen. Ich habe auch versucht, observeEvent zu verwenden, aber das hat auch nicht funktioniert. Ich kann nicht herausfinden, warum, da ich die gleiche Code-Struktur für eine selectInput verwendet und alles hat gut funktioniert.

ich ein kleines reproduzierbaren Beispiel erstellt haben:

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) 

Antwort

2

Scheint, wie das Problem wahrscheinlich mit war:

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

So kommentierte ich, dass herausstellte, hatte auch in zu Difference als Difference() beziehen Ihre Datatable Anruf. Und machte die Änderung dieser Datentabelle abhängig von 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)