我正在尝试创建一个小应用程序来读取一些参数(如textInput
)并相应地更改数据框,但看起来它并没有真正读取输入。
如果我打开应用程序,插入参数,然后单击提交没有任何反应,我仍然无法看到数据帧。我也尝试使用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)
答案 0 :(得分:2)
似乎问题可能与:
div(style = 'overflow-x: scroll', tableOutput('table'))
所以我评论说,在你的数据表调用中也必须将Difference
称为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)