【发布时间】:2018-10-19 22:06:17
【问题描述】:
我有一个要加载到 Shiny 应用程序中的数据库。我有用户必须输入的闪亮输入。我试图让它在我按下“提交”时将提交的数据附加到 data.frame 的底部。
我有下面的代码。我希望我的 Testdata data.frame 附加输入数据。我敢肯定我想太多了,但希望能得到任何帮助。我最初的想法是根据按下提交按钮时的 rbind 或附加响应式 data.frame,但我无法弄清楚。
library(shiny)
library(plotly)
library(DT)
shinyApp(
ui = navbarPage("Testing the saving to dataframes",
tabPanel("Plot",
mainPanel(
textInput("company", "Company Name", ""),
textInput("poc", "Point of Contact", ""),
textInput("sales_rep", "Sales Rep", ""),
sliderInput('chanceofsale',"Probability of Sale", min=1, max=10,value=5),
actionButton("submit", strong("Submit"))
)
),
tabPanel("Table",
DT::dataTableOutput("Test_Table")
)
),
server = function(input, output) {
Testdata = data.frame("company" = "company", "poc" = "poc","sales_rep" = "rep","chanceofsale" = "5")
output$Test_Table = renderDataTable({
datatable(Testdata
)
})
}
)
编辑:尝试根据反馈绑定数据框的代码:
library(shiny)
library(plotly)
library(DT)
fieldsAll = c("company","poc","sales_rep","chanceofsale")
shinyApp(
ui = navbarPage("Testing the saving to dataframes",
tabPanel("Plot",
mainPanel(
textInput("company", "Company Name", ""),
textInput("poc", "Point of Contact", ""),
textInput("sales_rep", "Sales Rep", ""),
sliderInput('chanceofsale',"Probability of Sale", min=1, max=10,value=5),
actionButton("submit", ("Submit"))
)
),
tabPanel("Table",
DT::dataTableOutput("Combined_Table")
)
),
server = function(input, output) {
#Initial Dataframe
Testdata <- data.frame("company" = "company", "poc" = "poc",
"sales_rep" = "rep", "chanceofsale" = "5")
observeEvent(input$submit, {
Testdata <- rbind(Testdata,
data.frame("company" = input$company, "poc" = input$poc,
"sales_rep" = input$sales_rep,
"chanceofsale" = as.character(input$chanceofsale))
)
})
output$Test_Table = DT::renderDataTable(Testdata)
}#Server End
)
【问题讨论】:
-
我最初的想法是 rbind 或附加响应式 data.frame ...您是否尝试过最初的想法?如果是这样,发生了什么?错误?不想要的结果?你的数据库在哪里?
-
@Parfait,我尝试创建一个反应式 data.frame 来接收输入值并将现有的 data.frame 与新的数据框合并,但它失败了。我从这个示例中查看了我的数据库,并创建了 Testdata 来模仿它。
-
你能发布你的试用代码和错误信息/不想要的结果吗?