R Shiny:在用户更改输入后更新数据框
R Shiny: Update a Dataframe after a user's change of input
我现在尝试更改具有以下结构的现有数据框的时间太长了:
A<-c(1,NA)
B<-c(2,NA)
df<-data.frame(A,B)
>df
A B
1 1 2
2 NA NA
我想在 UI 中显示数据框,并更改一个 csv 文件并用数据框的数据覆盖它。
我想达到的路径:
- 数据帧最初加载到 R 中。
- 用户在应用程序的滑块上选择一个值。然后这个值应该写入A2以覆盖NA。之后整个事情应该被写入一个 CSV 文件。
到目前为止问题的孤立部分:
library("shiny")
x<- .. #(csvupload)
ui <- fluidPage(
#Copy of x
xchange<-x
#The slider where the user chooses a value
sliderInput("slider", label = "Slider", min = 0,
max = 3,step=0.001, value =1),
#Print of the changed database
textOutput("xchange"))
server<-function(input,output,session){
observeEvent(input$Slider,{
x$A[x$Szenarios=="2"]<-input$slider
})
output$xchange<-renderValues({
input$x})
}
我收到错误:
Error code:argument should be a character vector of length 1
all but the first element will be ignored
Warning: Error in reactiveValues: All arguments passed to reactiveValues() must be named.
我猜我使用了 observeEvent、renderValues 或两者都错了,或者 textOutput 在这里使用不是个好主意。但是..我不知道...
我真的不需要打印它,但我认为这可能是控制我所做的是否正确的最佳方式。
这可能对你有用。上传和写入的所有不同版本的数据有点不稳定。
library("shiny")
ui <- fluidPage(
#The slider where the user chooses a value
sliderInput("slider", label = "Slider", min = 0,
max = 3,step=0.001, value =1),
#Print of the changed database
textOutput("xchange")
)
server<-function(input,output,session){
#Read data into server not ui
data<-read.csv("x")
#Re-read data for any changes, write to csv new changes, ignore startup
observeEvent(input$slider,{
data<-read.csv("x")
data$A[2]<-input$slider
write.csv(data,"data.csv")
ignoreInit=T
})
#Reactive variable xchange that updates the values of data
xchange<-reactive({
data<-read.csv("x")
data$A[2]<-input$slider
data
})
#Display the most recent file, with the most recent changes
output$xchange<-renderTable({
xchange()
})
}
我现在尝试更改具有以下结构的现有数据框的时间太长了:
A<-c(1,NA)
B<-c(2,NA)
df<-data.frame(A,B)
>df
A B
1 1 2
2 NA NA
我想在 UI 中显示数据框,并更改一个 csv 文件并用数据框的数据覆盖它。
我想达到的路径:
- 数据帧最初加载到 R 中。
- 用户在应用程序的滑块上选择一个值。然后这个值应该写入A2以覆盖NA。之后整个事情应该被写入一个 CSV 文件。
到目前为止问题的孤立部分:
library("shiny")
x<- .. #(csvupload)
ui <- fluidPage(
#Copy of x
xchange<-x
#The slider where the user chooses a value
sliderInput("slider", label = "Slider", min = 0,
max = 3,step=0.001, value =1),
#Print of the changed database
textOutput("xchange"))
server<-function(input,output,session){
observeEvent(input$Slider,{
x$A[x$Szenarios=="2"]<-input$slider
})
output$xchange<-renderValues({
input$x})
}
我收到错误:
Error code:argument should be a character vector of length 1
all but the first element will be ignored
Warning: Error in reactiveValues: All arguments passed to reactiveValues() must be named.
我猜我使用了 observeEvent、renderValues 或两者都错了,或者 textOutput 在这里使用不是个好主意。但是..我不知道...
我真的不需要打印它,但我认为这可能是控制我所做的是否正确的最佳方式。
这可能对你有用。上传和写入的所有不同版本的数据有点不稳定。
library("shiny")
ui <- fluidPage(
#The slider where the user chooses a value
sliderInput("slider", label = "Slider", min = 0,
max = 3,step=0.001, value =1),
#Print of the changed database
textOutput("xchange")
)
server<-function(input,output,session){
#Read data into server not ui
data<-read.csv("x")
#Re-read data for any changes, write to csv new changes, ignore startup
observeEvent(input$slider,{
data<-read.csv("x")
data$A[2]<-input$slider
write.csv(data,"data.csv")
ignoreInit=T
})
#Reactive variable xchange that updates the values of data
xchange<-reactive({
data<-read.csv("x")
data$A[2]<-input$slider
data
})
#Display the most recent file, with the most recent changes
output$xchange<-renderTable({
xchange()
})
}