我从一个闪亮的例子开始研究这个谷歌形式,它已经扩展了我想对数字输入进行排序并显示用户何时保存数据的最后一个ID = rowname = entry,其他数值变量很明显。你可以在服务器上看到我的失败,如果有人知道如何在关闭之后运行下一个块我会很感激。
也很抱歉葡萄牙语,如果你想让我在表格框中翻译一些东西,请随时询问。
---
title: "R Notebook"
output: html_notebook
---
```{r}
library(shiny)
library(shinydashboard)
library(DT)
####Functions Used in saving and closing file####
saveData <- function(data) {
data <- as.data.frame(t(data))
if (exists("responses")) {
responses <<- rbind(responses, data)
} else {
responses <<- data
}
ultimaresposta <<- data
}
loadData <- function() {
if (exists("responses")) {
responses
}
}
# Define the fields we want to save from the form
fields <-
c(
"NameDataSet",
"Uses_dummies",
"NameDummies",
"HowToSaveDummies",
"HowToSaveSimple",
"WhereToSave",
"Date",
"Frequency",
"Forecast",
"Confidence_Intervals",
"Starting_Variable",
"Finishing_Variable"
)
ui <- dashboardPage(
dashboardHeader(title = "Forecaster"),
dashboardSidebar(sidebarMenu(
menuItem("Dashboard", tabName = "dashboard"),
menuItem("Raw data View", tabName = "rawdata")
)),
# Body do dashboard principal----
dashboardBody(tabItems(
tabItem(
"dashboard",
fluidPage(div(
style = 'overflow: auto',
width = 12,
DT::dataTableOutput('responses')
)),
tags$hr(),
# soh funciona
div(
style = 'overflow: auto',
box(
title = "Title 1",
width = 12,
solidHeader = TRUE,
status = "primary",
fluidPage(fluidRow(
column(
6,
selectInput(
'NameDataSet',
'Nome dos dados',
multiple = FALSE,
Filter(function(x)
is.data.frame(get(x)), ls())
),
checkboxInput("Uses_dummies", "Vamos usar Dummies?", FALSE),
conditionalPanel(
condition = "input.Uses_dummies == true",
selectInput(
'NameDummies',
'Nome das Dummies',
multiple = FALSE,
Filter(function(x)
is.data.frame(get(x)), ls())
)
),
conditionalPanel(
condition = "input.Uses_dummies == true",
textInput(
"HowToSaveDummies",
"Como Vamos Chamar essa regressao com dummies?, tem que terminar com .csv",
"exemplodesalvardummies.csv"
)
),
conditionalPanel(
condition = "input.Uses_dummies == false",
textInput(
"HowToSaveSimple",
"Como Vamos Chamar essa regressao simples?, tem que terminar com .csv?",
"exemplodesalvarsimples.csv"
)
),
textInput(
"WhereToSave",
"Onde vamos salvar suas regressoes pode ignorar",
"~/R"
),
dateInput(
'Date',
label = "Quando Foi o primeiro dia dos seus dados?",
value = Sys.Date(),
format = "dd/mm/yy",
language = "pt-BR"
)
),
column(
6,
numericInput("Frequency", "Qual eh a frequencia do seus dados?", value = 12),
numericInput("Forecast", "Quantos periodos de forecast?", value = 12),
textInput(
"Confidence_Intervals",
"qual sao os intervalos de confianca que voce gostaria? Dica deixe 0 para nao colocar nenhum",
"80,95"
),
numericInput(
"Starting_Variable",
"Qual a primeira coluna que vamos usar no forecast?",
value = 1
),
numericInput(
"Finishing_Variable",
"Qual a ultima coluna que vamos usar no forecast?:Dica se deixar no default vamos usar todas as variaveis",
value = 10000
),
actionButton("submit", "Salvar"),
bootstrapPage(
tags$button(
id = 'close',
type = "button",
class = "btn action-button",
onclick = "setTimeout(function(){window.close();},500);",
# close browser
"Close window"
)
)
)
))
)
)
),
tabItem("rawdata",
fluidPage(
selectInput(
'df_picker',
'Pick dataframe',
Filter(function(x)
is.data.frame(get(x)), ls())
),
DT::dataTableOutput("df", width = 300)
))
))
)
#Server
server = function(input, output, session) {
# Whenever a field is filled, aggregate all form data
formData <- reactive({
data <- sapply(fields, function(x)
input[[x]])
data
})
# When the Submit button is clicked, save the form data
observeEvent(input$submit, {
saveData(formData())
})
# Show the previous responses
# (update with current response when Submit is clicked)
output$responses <- DT::renderDataTable({
input$submit
options(DT.options = list(
pageLength = 1
))
loadData()
}, colnames = c('ID' = 1), filter = ("top"),as.numeric(1:12))
#Data table for view
output$df <- DT::renderDataTable({
get(input$df_picker)
})
# stop shiny
observe({
if (input$close > 0)
stopApp()
})
}
#### Preview the UI in the console(Shiny App)####
shinyApp(ui = ui, server = server)
```
答案 0 :(得分:0)
如果我理解你,你需要将服务器中的提交部分更改为:
# When the Submit button is clicked, save the form data
observeEvent(input$submit, {
saveData(formData())
updateSelectInput(
session = session,
inputId = "df_picker",
choices = names(which(unlist(eapply(.GlobalEnv,is.data.frame))))
)
})
如您所见,您需要更新您的输入,我也会更改获取数据帧的代码,而您的变体不起作用..