library(shiny)
shinyUI(fluidPage(
titlePanel("Trying to reset text !"),
sidebarLayout(
sidebarPanel(
actionButton("button1","Print text")
),
mainPanel(
textOutput("textToPrint"),
br(),
uiOutput("uiButton2")
)
)
))
shinyServer(function(input, output) {
output$textToPrint <- renderText({
if(input$button1==0) (return(""))
else (return("Button clicked"))
})
output$uiButton2 <- renderUI({
if(input$button1==0) (return ())
else (return(actionButton("button2","Reset text and this button")))
})
})
I wish I click on button2 and it executes some code to replace "Print text" by "" and remove actionButton "button2".I wanted to reset the value of input$button1 to 0, but it's not permitted.I guess it's possible to do it without Javascript, but I'm curious about your method too.
Le lundi 16 juin 2014 16:10:08 UTC+2, Mart Vogel a écrit :
I'm not totally sure what you are trying to do, but it sounds like you could easily solve it with some javascriptbloemen.jpg
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
ui <- fluidPage( sliderInput(inputId = "Param", label = "Free Param", min = 0, max = 10, value = 0), actionButton(inputId = "AutoParam", label = "Find the optimal Param"), plotOutput(outputId = "ParamPlot"))
server <- function(input, output, session) { v <- reactiveValues(valueButton = 0) # # Each time button is click, add 1 to custom value of the button observeEvent(input$AutoParam, { v$valueButton = v$valueButton + 1 updateSliderInput(session, inputId = "Param", value = 5) updateActionButton(session, inputId = "AutoParam", label = "Param set to 5") }) # Change on sliderInput observeEvent(input$Param, { # If change on slider is because of button, v$valueButton==1 if(v$valueButton==0) { updateActionButton(session, inputId = "AutoParam", label = "Find the optimal Param") } # reset value of valueButton v$valueButton = 0 }) output$ParamPlot <- renderPlot({Thank you Matthieu, that's exactly what I needed!
I will try to adapt it to my real code.
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/77772f71-e369-4b42-a341-248d93325c4d%40googlegroups.com.
ui <- fluidPage(
sliderInput("Param1", label = "Param 1",
min = 0,
max = 10,
value = 0),
sliderInput("Param2", label = "Param 2",
min = 0,
max = 10,
value = 0),
sliderInput("Param3", label = "Param 3",
min = 0,
max = 10,
value = 0),
sliderInput("Param4", label = "Param 4",
min = 0,
max = 10,
value = 0),
actionButton(inputId = "AutoParam", label = "Find the optimal Param"),
plotOutput(outputId = "ParamPlot"),
tableOutput("Criteria")
)
server <- function(input, output, session) {
RES <- reactive({
v <- reactiveValues(valueButton = 0)
# Each time button is click, add 1 to custom value of the button
MOD2 <- eventReactive(input$AutoParam, {
v$valueButton = v$valueButton + 1
Param1 <- 1
Param2 <- 2
Param3 <- 3
Param4 <- 4
VAL <- Param1 + Param2 + Param3 + Param4
updateSliderInput(session, inputId = "Param1", value = Param1)
updateSliderInput(session, inputId = "Param2", value = Param2)
updateSliderInput(session, inputId = "Param3", value = Param3)
updateSliderInput(session, inputId = "Param4", value = Param4)
updateActionButton(session, inputId = "AutoParam", label = "Auto")
return(list(VAL = VAL))
})
# Change on sliderInput
MOD1 <- eventReactive({input$Param1 ; input$Param2 ; input$Param3 ; input$Param4}, {
# If change on slider is because of button, v$valueButton==1
if (v$valueButton == 0) {
Param1 <- input$Param1
Param2 <- input$Param2
Param3 <- input$Param3
Param4 <- input$Param4
VAL <- Param1 + Param2 + Param3 + Param4
updateActionButton(session, inputId = "AutoParam", label = "reactiveValues() in a global reactive()")
return(list(VAL = VAL))
}
# reset value of valueButton
v$valueButton <- 0
})
if (v$valueButton == 0) {
MOD <- MOD1()$VAL
isolate(MOD1())
} else {
MOD <- MOD2()$VAL
}
IDX <- MOD * 2
return(list(MOD = MOD, IDX = IDX))
})
output$ParamPlot <- renderPlot({
print(str(RES()$MOD))
plot(RES()$MOD, RES()$MOD, main = "",
xlim = c(0, 40), ylim = c(0, 40))
})
output$Criteria <- renderTable({
data.frame(Param = c(RES()$MOD, RES()$IDX))
})
}
shinyApp(ui, server)To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/0481de6a-547f-444f-a827-1ce105778ab2%40googlegroups.com.
MOD1 <spa