【发布时间】:2020-12-21 17:49:19
【问题描述】:
我正在尝试根据 sliderInput 的输出设置数据框。
这是我的代码:
runApp(
list(
ui = dashboardPage(
dashboardHeader(title = "Crédit"),
dashboardSidebar(
sidebarMenu(
menuItem("Visualisation des données", tabName = "visualization", icon = icon("poll"))
)),
dashboardBody(
tabItems(
# visualization
tabItem(tabName = "visualization",
h1("Visualisation des données"),
h2("Exploration du tableau"),
dataTableOutput('dataTable'),
h2("Graphiques"),
fluidRow(
column(5, plotOutput("Plot1")),
column(4,dateRangeInput("dates", label = h3("Date range"),
start = as.Date("1972-09-30"))
),
column(4,
sliderInput("slider", label = h3("Slider"), min = 0,
max = 5, value = 1, step = 0.5),
column(6,
dataTableOutput('my_table')
)))
)
)))
, server = function(input, output) {
myReactives <- reactiveValues(credit = Credit_Defaut)
output$dataTable = DT::renderDataTable(Credit_Defaut[1:100,])
a <- reactive({as.data.frame(matrix(data = NA, nrow = (length(seq(0,10,input$slider))-1), ncol = 1))})
b <- reactive({as.data.frame(matrix(data = NA, nrow = (length(seq(0,10,input$slider))-1), ncol = 1))})
df <- reactive({as.data.frame(matrix(data = c(paste0("[", seq(0,10,input$slider)[1],";",seq(0,10,input$slider)[2],"]"),
for (i in 2:(length(seq(0,10,input$slider))-2)){
a()[i-1] <- paste0("]", seq(0,10,input$slider)[i],";",seq(0,10,input$slider)[i+1],"]")},a(),
paste0("]", max(seq(0,10,input$slider)),";","Inf","["),
nrow(myReactives$credit[which(myReactives$credit$Defaut>=seq(0,10,input$slider)[1] & myReactives$credit$Defaut<=seq(0,10,input$slider)[2]),]),
for (i in 2:(length(seq(0,10,input$slider))-2)){
b()[i-1] <- nrow(myReactives$credit[which(myReactives$credit$Defaut>seq(0,10,input$slider)[i] & myReactives$credit$Defaut<=seq(0,10,input$slider)[i+1]),])},
b(),
nrow(myReactives$credit[which(myReactives$credit$Defaut>max(seq(0,10,input$slider))),])),nrow = (length(seq(0,10,input$slider))-1), ncol = 2))})
output$my_table <- renderDataTable({
df()
})
}))
首先,我只想检查我得到的数据帧是否正确。但是我有以下错误:
Warning: Error in <-: invalid (NULL) left side of assignment
我认为这是由于我的 for 循环中的“a”和“b”。我不知道我是否在我的向量中正确调用了它们。
有人遇到过这个问题吗?
提前感谢那些将投资解决我的问题的人。
【问题讨论】:
-
如果我听说“Shiny 的可编辑 data.frame”我会想到
rhandsontable -
看了之后,我觉得这不是我要找的。我只想考虑 SliderInput 的输出,以便在设计时使用它来创建数据框。但是谢谢你提供这个。
标签: r dataframe shiny reactive