如何通过单击按钮翻转闪亮的形状? [英] How to flip up shapes in shiny by clicking a button?
本文介绍了如何通过单击按钮翻转闪亮的形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我闪亮的应用程序中包含一个语义形状元素(形状:https://semantic-ui.com/modules/shape.html#/usage).我可以使用 shinyjs
和 shiny.semantic
构建形状.但是我不知道如何创建一个通过点击来翻转形状的按钮.
I want to include a semantic shape element in my shiny app (shapes:
https://semantic-ui.com/modules/shape.html#/usage).
I am able to construct the shape by using shinyjs
and shiny.semantic
.
But I don't know how to create a button that flips the shape by clicking on it.
这里有一个例子:
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)
})
这会创建按钮和形状,但如何让按钮翻转形状?
This creates both the button and a shape, but how do I make the button flipping the shape?
推荐答案
我认为你需要这个 JS 代码:
I think you need this JS code:
jsCode <- "
$('.shape').shape();
$('#test').on('click', function(){$('.shape').shape('flip up');});
"
或者只是:
jsCode <- "
$('.shape').shape();
"
在用户界面中:
tags$button(id="test", class="ui button", "Flip", onclick="$('.shape').shape('flip up');")
这篇关于如何通过单击按钮翻转闪亮的形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文