A piece of an app I am building takes input from clip
which is designed for excel tables on clipboard. I want it to be converted to data.frame using clipr::read_clip_tbl()
. This works well. But, for each time the clip
actionButtonis triggered, I want the output from
table2to be updated by binding the rows from each dataframe when
clipis clicked. Instead, each time
clip“` is triggered, it only shows the most recent data frame.
Any advice?
This is the part in question:
<code> c <- reactiveValues(value=0)
observeEvent(input$clip, {
c$value <- c$value+1
})
table2 <- eventReactive(input$clip, {
read_clip_tbl() %>%
mutate(exp = c$value) %>%
bind_rows()
})
</code>
<code> c <- reactiveValues(value=0)
observeEvent(input$clip, {
c$value <- c$value+1
})
table2 <- eventReactive(input$clip, {
read_clip_tbl() %>%
mutate(exp = c$value) %>%
bind_rows()
})
</code>
c <- reactiveValues(value=0)
observeEvent(input$clip, {
c$value <- c$value+1
})
table2 <- eventReactive(input$clip, {
read_clip_tbl() %>%
mutate(exp = c$value) %>%
bind_rows()
})
But this is the full code:
<code>library(shiny)
library(dplyr)
library(shinydashboard)
library(clipr)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
actionButton('clip', 'Copy from clipboard'),
actionButton("go", "Go")
),
dashboardBody(
tags$style(type="text/css",
".shiny-output-error { visibility: hidden; }",
".shiny-output-error:before { visibility: hidden; }"
),
plotOutput('plot1'),
tableOutput( 'table1'),
tableOutput( 'table2')
)
)
server <- function(input, output, session) {
c <- reactiveValues(value=0)
observeEvent(input$clip, {
c$value <- c$value+1
})
table2 <- eventReactive(input$clip, {
read_clip_tbl() %>%
mutate(exp = c$value) %>%
bind_rows()
})
plot1 <- eventReactive(input$go, {
read_clip_tbl() %>%
mutate(treatment.name = as.factor(treatment.name)) %>%
mort(plot_only=T)
})
table1 <- eventReactive(input$go, {
read_clip_tbl() %>%
mutate(treatment.name = as.factor(treatment.name)) %>%
mort(table_only=T)
})
output$table2<- renderTable({
req(table2())
table2()
})
output$plot1<- renderPlot({
req(plot1())
plot1()
})
output$table1<- renderTable({
req(table1())
table1()
})
}
shinyApp(ui, server)
</code>
<code>library(shiny)
library(dplyr)
library(shinydashboard)
library(clipr)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
actionButton('clip', 'Copy from clipboard'),
actionButton("go", "Go")
),
dashboardBody(
tags$style(type="text/css",
".shiny-output-error { visibility: hidden; }",
".shiny-output-error:before { visibility: hidden; }"
),
plotOutput('plot1'),
tableOutput( 'table1'),
tableOutput( 'table2')
)
)
server <- function(input, output, session) {
c <- reactiveValues(value=0)
observeEvent(input$clip, {
c$value <- c$value+1
})
table2 <- eventReactive(input$clip, {
read_clip_tbl() %>%
mutate(exp = c$value) %>%
bind_rows()
})
plot1 <- eventReactive(input$go, {
read_clip_tbl() %>%
mutate(treatment.name = as.factor(treatment.name)) %>%
mort(plot_only=T)
})
table1 <- eventReactive(input$go, {
read_clip_tbl() %>%
mutate(treatment.name = as.factor(treatment.name)) %>%
mort(table_only=T)
})
output$table2<- renderTable({
req(table2())
table2()
})
output$plot1<- renderPlot({
req(plot1())
plot1()
})
output$table1<- renderTable({
req(table1())
table1()
})
}
shinyApp(ui, server)
</code>
library(shiny)
library(dplyr)
library(shinydashboard)
library(clipr)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
actionButton('clip', 'Copy from clipboard'),
actionButton("go", "Go")
),
dashboardBody(
tags$style(type="text/css",
".shiny-output-error { visibility: hidden; }",
".shiny-output-error:before { visibility: hidden; }"
),
plotOutput('plot1'),
tableOutput( 'table1'),
tableOutput( 'table2')
)
)
server <- function(input, output, session) {
c <- reactiveValues(value=0)
observeEvent(input$clip, {
c$value <- c$value+1
})
table2 <- eventReactive(input$clip, {
read_clip_tbl() %>%
mutate(exp = c$value) %>%
bind_rows()
})
plot1 <- eventReactive(input$go, {
read_clip_tbl() %>%
mutate(treatment.name = as.factor(treatment.name)) %>%
mort(plot_only=T)
})
table1 <- eventReactive(input$go, {
read_clip_tbl() %>%
mutate(treatment.name = as.factor(treatment.name)) %>%
mort(table_only=T)
})
output$table2<- renderTable({
req(table2())
table2()
})
output$plot1<- renderPlot({
req(plot1())
plot1()
})
output$table1<- renderTable({
req(table1())
table1()
})
}
shinyApp(ui, server)