有闪亮的反应性问题
我尝试显示与Selecinput标准匹配的行数,并有可能添加注释。 每次有人添加评论时,它都会添加一行,我想更新行数。 (实际上,我正在处理一个评论部分,我想在其中显示播放器中的所有注释并显示提交的所有新评论)
,以输出$ texte,当SelectInput更改时,DF是子集,因此反应性工作。当我有观察到的时,DF就会保存,但没有反应性。当我切换选定的播放器时,它永远不会考虑到DF的变化,就像他一次导入DF并且从未为显示器更新它。
感谢您的帮助
df<-data.frame(nom=c("name1","name2","name3","name"1),
comment=c("comment 1","comment 2","comment 3","comment4"))
ui<- sidebarLayout(
sidebarPanel(
selectInput(
inputId="select_j",
label="choose name",
choices=c("name1","name2","name3")
)
),
mainPanel(
fluidRow(textOutput("texte")),
fluidRow(textInput(
inputId = "comment",
label="Make a comment")),
actionButton("submit", "Submit"))
)
server<-function(input,output){
df_filter=reactive({df %>% subset(nom %in% input$select_j)})
observeEvent(input$submit,{
new_line=c(input$select_j,input$comment)
df[nrow(df) + 1,] <- new_line
write.csv2(df,"save.csv")
})
output$texte <- renderText({
input$submit
nrow(df_filter())
})
}
shinyApp(ui, server)
I try to display the number of lines that matchs selecinput criteria with a possibility to add comment.
Everytime someone add a comment, it s add a line, and i would like to update the number of line.
(Actually i am working on a comment section where I want to display all the comments from a player and display every new comment submitted)
For the output$texte, when the selectinput changes, the df is subset, so the reactive works. When i have an observeEvent, df is saved, but there is no reactivity. when I switch the selected players, it never take into account the change in df, it's like he imports df once and never update it for the display.
Thanks for your help
df<-data.frame(nom=c("name1","name2","name3","name"1),
comment=c("comment 1","comment 2","comment 3","comment4"))
ui<- sidebarLayout(
sidebarPanel(
selectInput(
inputId="select_j",
label="choose name",
choices=c("name1","name2","name3")
)
),
mainPanel(
fluidRow(textOutput("texte")),
fluidRow(textInput(
inputId = "comment",
label="Make a comment")),
actionButton("submit", "Submit"))
)
server<-function(input,output){
df_filter=reactive({df %>% subset(nom %in% input$select_j)})
observeEvent(input$submit,{
new_line=c(input$select_j,input$comment)
df[nrow(df) + 1,] <- new_line
write.csv2(df,"save.csv")
})
output$texte <- renderText({
input$submit
nrow(df_filter())
})
}
shinyApp(ui, server)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案(也许不是唯一的解决方案)。
df
必须设置为reactiveVal
,然后在观察事件时进行更新I have found the solution (maybe not the only one).
The
df
has to be set as areactiveVal
and then update when observe event