Barbara
Barbara

Reputation: 1168

Issue with text input in Shiny app

I'm trying to create a small app that reads some parameters (as textInput) and changes the data frame accordingly, but it looks like it's not really reading the input.

If I open the app, insert the parameters, and then click submit nothing happens, I still cannot see the dataframe. I have also tried using observeEvent but that didn't work either. I can't figure out why since I used the same code structure for a selectInput and everything worked fine.

I have created a small reproducible example:

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)

Upvotes: 0

Views: 537

Answers (1)

Balter
Balter

Reputation: 1095

Seems like the problem was probably with:

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

So I commented that out, also had to refer to Difference as Difference() in your datatable call. And made the changing of that datatable depend on 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)

Upvotes: 2

Related Questions