如何通过单击按钮翻转闪亮的形状?
How to flip up shapes in shiny by clicking a button?
我想在我闪亮的应用程序中包含一个语义形状元素(形状:
https://semantic-ui.com/modules/shape.html#/usage)。
我可以使用 shinyjs
和 shiny.semantic
来构建形状。
但是我不知道如何创建一个点击翻转形状的按钮。
举个例子:
Ui.R:
library(shiny)
# Define UI for application that draws a histogram
shinyUI(semanticPage(
shinyjs::useShinyjs(),
div(class="ui text shape",
div(class="sides",
div(class="ui header side active","This side starts visible."),
div(class="ui header side","This is yet another side"),
div(class="ui header side","This is the last side")
)
),
tags$button(id="test",class="ui button","Flip")
))
Server.R:
library(shiny)
library(shinyjs)
#devtools::install_github("Appsilon/shiny.semantic")
library(shiny.semantic)
#devtools::install_github("Appsilon/highlighter")
library(highlighter)
jsCode <- "
$('.shape').shape();
$('.shape').shape('flip up');
$('test').shape('flip up');
"
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
runjs(jsCode)
})
这会同时创建按钮和形状,但如何让按钮翻转形状?
我认为你需要这段 JS 代码:
jsCode <- "
$('.shape').shape();
$('#test').on('click', function(){$('.shape').shape('flip up');});
"
或者只是:
jsCode <- "
$('.shape').shape();
"
并在 ui 中:
tags$button(id="test", class="ui button", "Flip", onclick="$('.shape').shape('flip up');")
我想在我闪亮的应用程序中包含一个语义形状元素(形状:
https://semantic-ui.com/modules/shape.html#/usage)。
我可以使用 shinyjs
和 shiny.semantic
来构建形状。
但是我不知道如何创建一个点击翻转形状的按钮。
举个例子:
Ui.R:
library(shiny)
# Define UI for application that draws a histogram
shinyUI(semanticPage(
shinyjs::useShinyjs(),
div(class="ui text shape",
div(class="sides",
div(class="ui header side active","This side starts visible."),
div(class="ui header side","This is yet another side"),
div(class="ui header side","This is the last side")
)
),
tags$button(id="test",class="ui button","Flip")
))
Server.R:
library(shiny)
library(shinyjs)
#devtools::install_github("Appsilon/shiny.semantic")
library(shiny.semantic)
#devtools::install_github("Appsilon/highlighter")
library(highlighter)
jsCode <- "
$('.shape').shape();
$('.shape').shape('flip up');
$('test').shape('flip up');
"
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
runjs(jsCode)
})
这会同时创建按钮和形状,但如何让按钮翻转形状?
我认为你需要这段 JS 代码:
jsCode <- "
$('.shape').shape();
$('#test').on('click', function(){$('.shape').shape('flip up');});
"
或者只是:
jsCode <- "
$('.shape').shape();
"
并在 ui 中:
tags$button(id="test", class="ui button", "Flip", onclick="$('.shape').shape('flip up');")